Misdeclaring "main"
Tim McDaniel
mcdaniel at uicsrd.csrd.uiuc.edu
Sat Jul 29 16:02:18 AEST 1989
This is cross-posted to comp.lang.c (original article's newsgroup) and
comp.std.c (I have standards questions). Followups have been
redirected to comp.std.c.
In article <13104 at bloom-beacon.MIT.EDU> scs at adam.pika.mit.edu (Steve
Summit) writes:
>The production
>
> struct { struct-decl-list } id (arg-list) decl-list compound-statement
>
>yields a function that cannot be (correctly) called, since no
>other object can be declared with a type-equivalent structure.
I'm not so sure. Separate compilation is allowed in C, but struct
tags (and their definitions) are not global in scope; for external
linkage, only the types and order of the struct's members matter.
I would think the following declarations are strictly conforming:
in foo.c:
extern struct { int f1; float f2; } func(); ...
in bar.c:
struct { int a6; float whacky; } func() ...
However, K&R 2, 1st edition, p. 213 says
A structure or union specifier with a list but no tag creates a
unique type; it can referred to directly only in the declaration
of which it is a part.
>The production
>
> struct tag { struct-decl-list } id (arg-list) ...
>
>yields a function that can only be called by routines appearing
>later in the same file.
This statement is even more problematical. How does it differ from
struct tag { struct-decl-list };
struct tag id (arg-list) ...
? If there is no difference, the "struct tag" declaration could just
as easily be in an include file, and another file could include it and
declare
extern struct tag id ();
Surely *this* behavior is blessed by the standard.
--
"Let me control a planet's oxygen supply, and I don't care who makes
the laws." - GREAT CTHUHLU'S STARRY WISDOM BAND (via Roger Leroux)
__
\ Tim, the Bizarre and Oddly-Dressed Enchanter
\ mcdaniel at uicsrd.csrd.uiuc.edu
/\ mcdaniel%uicsrd@{uxc.cso.uiuc.edu,uiuc.csnet}
_/ \_ {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel
More information about the Comp.lang.c
mailing list