prototypes required ?
Donald Lewine
lewine at dg-rtp.dg.com
Thu Oct 18 23:57:51 AEST 1990
In article <12826 at crdgw1.crd.ge.com>, volpe at underdog.crd.ge.com
(Christopher R Volpe) writes:
|>
|> Two questions:
|> 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? Or are old style
declarations
|> insufficient for ANY kind of function in a strictly conforming
|> program?
OK. See section 3.7.1: "If a function that accepts a variable number
of arguments is defined without a parameter type list that ends with
the ellipsis notation, the behavior is undefined."
This allows the compiler to generate a different calling sequence
for functions with a fixed number of argument and a variable number
of arguments. See section 4.8 in the rationale.
|>
|> 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?
Well, if the implementation uses one calling sequence (say, with
arguments in registers) for functions with a known number of arguments
and uses a different calling sequence (say, with arguments on the
stack) for functions with a variable number of arguments, the
generated code will not call the library correctly unless the function
is correctly declared. I will admit that you may not get an error
message, but the code will not work!
Note also that the definition of ANSI C was done to allow a compiler
to generate calls with arguments in registers and several new RISC
compilers take advantage of that.
--------------------------------------------------------------------
Donald A. Lewine (508) 870-9008 Voice
Data General Corporation (508) 366-0750 FAX
4400 Computer Drive. MS D112A
Westboro, MA 01580 U.S.A.
uucp: uunet!dg!lewine Internet: lewine at cheshirecat.webo.dg.com
More information about the Comp.std.c
mailing list