C Compiler bugs (was Re: Speaking of ksh)
Mat Waites
mat at emcard.UUCP
Fri Jun 10 04:15:43 AEST 1988
In article <532 at wrs.UUCP> owen at wrs.UUCP (Owen DeLong) writes:
]In article <4421 at haddock.ISC.COM> karl at haddock.ima.isc.com (Karl Heuer) writes:
]>In article <15085 at tut.cis.ohio-state.edu> lvc at tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes:
]>>Following up from comp.unix.wizards are amusing C Compiler bugs:
]>>Then there was the bug where if you had a structure declaration right before
]>>main and forget to end it with a ; the program would core dump on exit:
]>> struct blob { int a, b, c; } /* missing ; */
]>> main(argc, argv) ...
]>
]>Why should it be considered a "compiler bug" when a syntactically correct
]>program containing a user bug dumps core? It seems to me that the appropriate
]>"fix" is to make sure that lint complains about the mismatched declaration.
]>
]>Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
]>Followups to comp.lang.c.
]
]Tell me, Karl, where do you see the bug causing the program to dump core?
]
]I get the impression that the bug is in the compiler, and the compiler which
]doesn't need a ; (noted as missing) dumped core upon trying to return from
]function main.
[ I see a clue here! ]
]I see this as definitely being a compiler bug, particularly
]if you consider the code to be correct. It is conceivable to call the code
]incorrect (syntax error due to missing semicolon), but I would say that the
]compiler should actually accept the closing brace on a compound statement as
]an implied ; afterwards. If I'm wrong, flame me...I'll learn that way. If
]I'm not, we've all learned something. I would like to see the rest of the
]program which you must have seen to say it was a user bug.
]
]Owen
The program is syntactically correct. It declares a function named main
which returns a struct blob. Unfortunately the run-time system is not familiar
with blobs and will probably end up trashing the stack on exit.
If you'd written:
struct blob { int a, b, c; } /* missing ; */
bozo;
you'd have a struct blob called bozo. Why shouldn't main act the same way.
"main" is not a reserved word in general, although some compilers treat
it differently than other function names.
I think "the walking lint" is probably right about lint recognizing
main's appropriate return value type (although is seems to be
somewhat implementation dependant)
Mat
--
W Mat Waites | PHONE: (404) 727-7197
Emory Univ Cardiac Data Bank | UUCP: ...!gatech!emcard!mat
Atlanta, GA 30322 |
More information about the Comp.lang.c
mailing list