function declarators
Norman Diamond
diamond at jit345.swstokyo.dec.com
Tue Apr 2 15:13:14 AEST 1991
In article <14000 at darkstar.ucsc.edu> daniel at 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 at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
More information about the Comp.std.c
mailing list