🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2381

Re: Structure tags

#2381
From: Stephen Clamage
Date: Fri, 08 Feb 1991 17:06
45 lines
1707 bytes
t-itoh@utsm.nm.fujitsu.co.jp (Tsutomu Itoh) writes:

>1a.

>struct foo {int i;};
>struct foo;
>struct foo bar;

>1b.
>struct foo;
>struct foo {int i;};
>struct foo bar;

Both of these are ok.  In 1a there is no incomplete declaration.  In 1b,
line 1 is an incomplete declaration, completed in line 2, which is before
the complete declaration is needed.

>2a
>int bar(struct foo);
>struct foo {int i;};

This will not do what you want.  The scope of struct foo is the prototype
of function bar.  Any struct foo declared later, as in line 2, is a
different type from that in the prototype.  There is no way to pass an
argument to function bar, since no possible variable will be of a type
compatible with the struct foo in the prototype.  Not all compilers
get this right.  The prototype for bar is illegal in C++, by the way,
for exactly this reason.

>2b
>struct foo;
>int bar(struct foo);
>struct foo {int i;};

>Is the empty structure declaration necessary?

Some declaration is necessary for the reasons given above.  With a
declaration (complete or incomplete) for struct foo in scope when the
prototype for bar occurs, it is seen that bar takes an argument of that
same type struct foo.  In this case, the declaration of foo is completed
in line 3.

-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Technical Details
Message-ID: <595@taumet.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!taumet!steve
References: <4736@utsm.nm.fujitsu.co.jp>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!taumet!steve
From: steve@taumet.com (Stephen Clamage)
Newsgroups: comp.std.c
Subject: Re: Structure tags
Message-ID: <595@taumet.com>
Date: 8 Feb 91 17:06:52 GMT
References: <4736@utsm.nm.fujitsu.co.jp>
Organization: Taumetric Corporation, San Diego
Lines: 45