(j3.2006) Interesting F2003-ism
Malcolm Cohen
malcolm
Sun Feb 25 19:14:27 EST 2007
I wrote:
> What *is* entirely clear is that you have to call a function that is
> defined with an ellipsis with a prototype, and that prototype must
> use ellipsis the same as the function definition.
>
> This follows reasonably straightforwardly from p120 of c99.
...
> In fact my copy of gcc 3.4.4 doesn't allow it anyway:
> % cat junkz.c
> s1() { extern printf(char *,int); printf("%d",3); }
> s2() { extern printf(char *,float); printf("%e",3.5f); }
> % gcc junkz.c
> junkz.c: In function `s1':
> junkz.c:1: warning: conflicting types for built-in function 'printf'
> junkz.c: In function `s2':
> junkz.c:2: error: conflicting types for 'printf'
> junkz.c:1: error: previous declaration of 'printf' was here
Andy Vaught said:
> And yet, after all this, if a C compiler sees something like:
>
> void sub(void) {
> foo(1, 2, 3); /* No prototype of foo. Variable or fixed? */
Fixed. Can you not read? The C standard is absolutely explicit on this!
> }
>
> Somehow, it has to call foo(). It sounds like someone could make a
> conforming C compiler that would compile this program into something that
> would crash but no one will.
What program? You've given a single function of three lines!
If you mean an illegal program (e.g. foo doesn't have 3 int arguments),
you are wrong. C compilers have done that. There is more to the world
than pcc and gcc.
> And footnote 125 on p99 of C99 is:
>
> 125) If both function types are "old style", parameter types are not
> compared.
Exactly. "old style" means no prototype, and therefore, no ellipsis.
printf is not "old style"! It is illegal to call printf without a
prototype. (I remember the arguments about this quite well in the
mid-late 80s when ANSI C was being developed.)
> Probably not enough for you, but I'm going to allow people to do clever
> things.
For some value of the word "clever".
I'm boggled that you can seriously defend doing illegal C things when
even gcc (a paragon of mindless extension) forbids them! Oh and BTW
on at least one architecture even gcc turning a blind eye to the
illegalities (perhaps by separate compilation) would give the "wrong
answer" on your example. So go ahead, give your users silent wrong
answers instead of error messages.
Cheers,
--
........................Malcolm Cohen (malcolm at nag-j.co.jp), Nihon NAG, Tokyo.
More information about the J3
mailing list