prototypes required ?

diamond@tkovoa diamond at tkou02.enet.dec.com
Thu Oct 18 18:56:04 AEST 1990


In article <12826 at crdgw1.crd.ge.com> volpe at underdog.crd.ge.com (Christopher R Volpe) writes:

>  1) Can you point me to a reference in the standard that says that
>     old-style declarations are insufficient for a variable argument
>     function in a strictly conforming program?

Section 3.5.4.3 plus section 3.7.1 together do this.
Section 3.5.4.3, semantics, sixth paragraph:
  "If one type has a parameter list and the other type is specified by
  a function declarator that is not part of a function definition and
  that contains an empty identifier list, the parameter list shall not
  have an ellipsis terminator..."
  Thus, if there is a non-defining declaration of printf without a
  prototype, then all definitions and declarations of printf that
  do have prototypes must not have an ellipsis.
Section 3.7.1, semantics, second paragraph:
  "If a function that accepts a variable number of arguments is defined
  without a parameter list that ends with the ellipsis notation, the
  behavior is undefined."
  Thus, if printf's implementation is defined in ANSI C, it must be defined
  with a prototype that ends with an ellipsis.

If your <stdio.h> does not declare printf, and your library provides a
definition of printf that was not coded in ANSI C, then it seems that a
loophole allows you to make your own extern declaration of printf without
a proper prototype.  I would not suggest depending on this.

I didn't check if there's another loophole that might permit printf
to be called (with defined results) without any declaration at all, but 
it doesn't seem likely.  You know how to do that check.

>  2) Are you sure you answered the question he asked? Jeff asked if
>     it is valid for the compiler to REQUIRE YOU TO include the
>     prototype. To me, "require you to" means "refuse to generate
>     code unless you...". That's a different issue. Unless a program
>     violates a syntax rule or a semantic constraint, the compiler
>     can at most issue a warning but must still generate code. I
>     believe (please correct me if I'm wrong) that a program can
>     fail to be strictly conforming (and even fail to be conforming)
>     without violating any semantic constraints. Is this correct?

The standard does not really define "REQUIRE YOU TO", although the word
"shall" and the word "undefined" are meta-defined in a meta-standard.
I would say that a compiler can require you to include the prototype.
-- 
Norman Diamond, Nihon DEC    diamond at tkov50.enet.dec.com
                                    (tkou02 is scheduled for demolition)
We steer like a sports car:  I use opinions; the company uses the rack.



More information about the Comp.std.c mailing list