Article View: comp.std.c
Article #2863Re: Pointers to Incomplete Types in Prototypes
From: Mike Vermeulen
Date: Tue, 07 May 1991 00:56
Date: Tue, 07 May 1991 00:56
53 lines
2316 bytes
2316 bytes
> 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.
> Our HP "ANSI" C compiler is complaining about the above prototype
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.
I believe section 2.1.1.3 (see also footnote 6) allows a conforming
implementation to issue diagnostics such as the warning above, as long as it
correctly translates valid programs.
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.
While the standard allows incomplete types to be declared, and go out of
scope at the end of the parameter list; this is usually not what the user
desires. The warning was added to ease in diagnosing this problem.
> I want some ammunition before I report it to HP as a problem.
Consider it unofficially reported. Contact me if you have further questions
or concerns about the HP ANSI C compiler.
--mev, mev@hpcomet.hp.com
Standard disclaimer: speaking for myself and not HP.
Technical Details
Message-ID:
<7330008@hpfcso.FC.HP.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!hplabs!hpfcso!mevReferences:
<w!2g7+c@rpi.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!hplabs!hpfcso!mev From: mev@hpfcso.FC.HP.COM (Mike Vermeulen) Newsgroups: comp.std.c Subject: Re: Pointers to Incomplete Types in Prototypes Message-ID: <7330008@hpfcso.FC.HP.COM> Date: 7 May 91 00:56:08 GMT References: <w!2g7+c@rpi.edu> Organization: Hewlett-Packard, Fort Collins, CO, USA Lines: 53