C Compiler bugs (was Re: Speaking of ksh)
Avram Aronoff
aronoff at garfield
Fri Jun 17 20:01:13 AEST 1988
> Many, many people have written...
>| >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) ...
>...but why does the code dump core?
In the typical implementation of structure returns, a function returning a
structure is passed a hidden pointer as its first argument, and uses that
pointer to store the return value. Clearly, crt0.o assumes that main returns
an int, and so passes no pointer. Main is trying to stuff a structure using
argc as a pointer.
This is a programmer error, not a compiler error. In a hosted environment, the
system (albeit implicitly) assumes that main returns an int. Perhaps one of the
ANSI include files should be made to contain a prototype for main.
Hymie
More information about the Comp.lang.c
mailing list