home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19355 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  1.6 KB

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