prototypes required ?

Mark Hall markhall at pyrps5.pyramid.com
Fri Oct 19 10:04:16 AEST 1990


In article <18561 at haddock.ima.isc.com> karl at ima.isc.com (Karl Heuer) writes:
>In article <1964 at ccadfa.adfa.oz.au> Christopher-Vance at adfa.oz.au writes:
>>gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
>>| Yes, you definitely must have a prototype in scope [for printf()]
>>
>>Which means that gcc -ansi on a Pyramid cannot compile such a thing. I am
>>informed that the only way to make printf work is to *omit* the prototype.

There are two issues to cover here.  First, Doug said (quoting loosely)
"you must have a prototype in scope [for the *program* to be strictly
conforming]".  He didn't say that an ANSI compiler had to flag the
non-conformance.  Second, let me point out that on some architectures,
the calling sequence changes if you are calling a stdarg function (put
args on the stack instead of in registers, say).  If you don't have an
ellipsis prototype visible at the call site, the compiler will not know
to emit the correct calling sequence, and hence the program will die
mysteriously or give obscure results at runtime.  Does the ANSI
compiler which compiled this program have to tell you ahead of time
that you forgot the prototype?  No.  The adjective "conforming" applies
to programs, not compilers.

So does "gcc -ansi" really reject a program which calls a stdarg function 
without a prototype?  Does it manufacture a link-time check?  Otherwise,
how can it tell "printf" is a stdarg function?

>
>Presumably this is caused by having to link with the native implementation of
>printf(), and hence will be fixed when the FSF releases the GNU library.
>

I'm not sure what the problem is with the the Pyramid printf function
which is incompatible with gcc when you have an ellipsis prototype for 
printf.  Does gcc put ellipsis arguments on the stack or something?  
If so, why?

-Mark Hall (smart mailer): markhall at pyrps5.pyramid.com
	   (uucp paths): {ames|decwrl|sun|seismo}!pyramid!markhall



More information about the Comp.std.c mailing list