Article View: comp.std.c
Article #2865Re: Pointers to Incomplete Types in Prototypes
From: Norman Diamond
Date: Fri, 10 May 1991 01:10
Date: Fri, 10 May 1991 01:10
43 lines
2553 bytes
2553 bytes
In article <7330008@hpfcso.FC.HP.COM> mev@hpfcso.FC.HP.COM (Mike Vermeulen) writes:
>> extern void foo(struct bar *);
>> According to 3.1.2.5, struct bar is an incomplete type in this case,
>> and struct bar * is a pointer to an incomplete type.
>> I couldn't find anything in 3.5.4.3 that allows or forbids incomplete
>> types, or pointers to them, in function prototypes.
>
>Agreed. I don't think there is anything in the standard that forbids such
>an incomplete type in a parameter list.
>The HP ANSI C compiler issues the following warning:
> warning: struct 'bar' declared in parameter list will have scope
> limited to this function declaration or definition.
The problem, as someone else pointed out, is that struct 'bar'
IS NOT DECLARED in the parameter list. It is REFERENCED in the
parameter list.
If the declaration were
extern void foo(struct bar { /* fields */ } *);
then the HP ANSI C compiler's warning would be correct.
>The reason for the warning is to help in the diagnosis of a situation such as:
> /* header file contents */
> extern void foo(struct bar *);
> struct bar { /* fields */ };
> /* user code */
> #include HEADER
> struct bar *barp;
> main(){
> foo(barp);
> }
>In this program, the compiler will diagnose a mismatch in parameter types at
>the call to foo(). The reason is that the first "struct bar" in the parameter
>list goes out of scope at the end of the declaration; so the next declaration
>of "struct bar" in the header file declares a new (incompatible) structure
>type.
Sorry, no. There is only one declaration of a type "struct bar" in that
code, and it is referenced several times. There is no compatibility problem.
--
Norman Diamond diamond@tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Permission is granted to feel this signature, but not to look at it.
Technical Details
Message-ID:
<1991May10.011038.6781@tkou02.enet.dec.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!tkou02.enet.dec.com!jit533!diamondReferences:
<w!2g7+c@rpi.edu> <7330008@hpfcso.FC.HP.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!pa.dec.com!jrdzzz.jrd.dec.com!tkou02.enet.dec.com!jit533!diamond From: diamond@jit533.swstokyo.dec.com (Norman Diamond) Newsgroups: comp.std.c Subject: Re: Pointers to Incomplete Types in Prototypes Message-ID: <1991May10.011038.6781@tkou02.enet.dec.com> Date: 10 May 91 01:10:38 GMT References: <w!2g7+c@rpi.edu> <7330008@hpfcso.FC.HP.COM> Sender: usenet@tkou02.enet.dec.com (USENET News System) Reply-To: diamond@jit533.enet@tkou02.enet.dec.com (Norman Diamond) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 43