🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2661

Re: function declarators

#2661
From: Norman Diamond
Date: Tue, 02 Apr 1991 05:13
42 lines
2476 bytes
In article <14000@darkstar.ucsc.edu> daniel@terra.ucsc.edu (Daniel Edelson) writes:
>I have tried unsuccessfully to find an unambiguous statement....
>in the standard that allows or prohibits the following cases:
>	1) a function declaration that defines a new 
>	   type in the return type, and,
>	2) a function declaration that defines a new
>	   type in a parameter
Most of the allowed cases do not have specific statements for them.
If all allowed cases were specifically described, the document would
be larger than the universe.

>For example:
>	/* The return type of foo() defines a new type, struct S */
>	struct S { int a; } foo(void) { }
>	/* The parameter of bar() defines a new type, struct T */
>	void bar(struct T { int b; } p) { }

>Are these strictly conformant ANSI C code?
Yes.

>If so, in the above example, must ``struct S'' be given file scope? 

Since this is a DEFINITION (not just decaration) of foo, indeed it must be
at file scope.  Therefore the structure tag S has file scope.

If the declaration were  struct S { int a; } foo(void);
then the scope of S would depend on where the declaration is located.

>The function ``bar'' is not particularly
>useful because the only type-safe calls to it can be
>recursive calls, since ``struct T'' has block scope.

If structural equivalence (rather than name equivalence) is the rule, then
bar could be called with any struct that contains a single integer.

It has been asserted in this newsgroup that structural equivalence is the
rule within a single translation unit.  I have not found a statement about
this in the standard.  (The rule for equivalence among separate translation
units is neither of the above, and is specified.)
--
Norman Diamond       diamond@tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Technical Details
Message-ID: <1991Apr2.051314.5273@tkou02.enet.dec.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!tkou02.enet.dec.com!jit345!diamond
References: <14000@darkstar.ucsc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!tkou02.enet.dec.com!jit345!diamond
From: diamond@jit345.swstokyo.dec.com (Norman Diamond)
Newsgroups: comp.std.c
Subject: Re: function declarators
Message-ID: <1991Apr2.051314.5273@tkou02.enet.dec.com>
Date: 2 Apr 91 05:13:14 GMT
References: <14000@darkstar.ucsc.edu>
Sender: usenet@tkou02.enet.dec.com (USENET News System)
Reply-To: diamond@jit345.enet@tkou02.enet.dec.com (Norman Diamond)
Organization: Digital Equipment Corporation Japan , Tokyo
Lines: 42