In article <Yv*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>Old Wolf said:
>Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).
void f(void);
int main(void) { f(); }
No diagnostic message is required. For all the compiler knows, the
definition of f() is in another translation unit. But if it isn't,
you'll get a linker error, obviously.
Isn't the linker part of the implementation? So if a linker error
is required, that would mean the implementation as a whole must issue
a diagnostic.
N869 6.9 says:
[#5] An external definition is an external declaration that
is also a definition of a function or an object. If an
identifier declared with external linkage is used in an
expression (other than as part of the operand of a sizeof
operator), somewhere in the entire program there shall be
exactly one external definition for the identifier;
otherwise, there shall be no more than one.127)
This is *not* in a Constraints section, so it looks to me like it's
undefined behavior and the implementation (linker in this case) is allowed
to silently accept it or silently refuse to generate an executable.
(This seems reasonable to me. Consider this source file representing
a complete program:
--------
void read(void);
int main(void) { read(); return 0; }
--------
I would be surprised to find a Unix-hosted C implementation that fails
to compile this, but the executable may or may not behave sensibly.)
>Is the answer still the same if the function declaration was:
static void f(void);
Excellent question. As far as I can tell, there is still no requirement
for a diagnostic message (although of course the implementation is free
to provide one if it feels like so doing), but I could easily be wrong.
N869 6.9#3 (which *is* in a Constraints section) says:
Moreover, if an identifier declared with
internal linkage is used in an expression (other than as a
part of the operand of a sizeof operator), there shall be
exactly one external definition for the identifier in the
translation unit.
I don't think just a prototype is an "external definition" as defined
in #5, so it looks to me like using a function (or other object) that is
declared static and not defined in that translation unit is a constraint
violation.
dave
--
Dave Vandervies
dj******@csclub.uwaterloo.ca
Odd, that. My programs don't tend to make my computer systems fall over.
--Richard Heathfield in comp.lang.c