home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sun4nl!and!jos
- From: jos@and.nl (Jos Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: Interesting bug
- Message-ID: <4304@dozo.and.nl>
- Date: 7 Jan 93 09:24:20 GMT
- References: <92353.203941SML108@psuvm.psu.edu> <8GJ037B@math.fu-berlin.de>
- Organization: AND Software BV Rotterdam
- Lines: 35
-
- In article <8GJ037B@math.fu-berlin.de> rene@hamel.uucp (Rene Mueller) writes:
- |In article <92353.203941SML108@psuvm.psu.edu>, <SML108@psuvm.psu.edu> writes:
- ||> I had a program with code like
- ||>
- ||> void routine (x)
- ||> int *x;
- ||> {
- ||> int x;
- ||> }
- ||>
- ||> My compiler did not trap this as an error... Shouldn't it? Or at least
- ||> give a warning?
-
- |No, it should'nt give even a warning...
- |Cause you open a new block with '{', and inside a new block you can define a NEW
- |variable with an 'old' name...
- |That mean that you will see the functionparameter right after the closing bracket
- |'}', but that's too late....
-
- Sorry, you're wrong. The compiler should start whining and set this program
- on fire 'till its dead and gone. This is definitely an error. Read the
- ANSI C standard: 3.1.2.1 Scope of identifiers:
-
- `If the declarator or type specifier that declares the identifier appears
- inside a block or within the list of parameter declarations in a function
- definition, the identifier has block scope, which terminates at the } that
- closes the associated block.'
-
- Both identifiers `x' in the code above have the same block scope, so this
- is an invalid redefinition of the identifier `x'. The compiler should not
- only give a warning, it should give an error message.
-
- kind regards,
-
- Jos aka jos@and.nl
-