Prototypes and ID lists

Walter Murray walter at hpclwjm.HP.COM
Wed Jul 19 07:48:42 AEST 1989


John F. Haugh II writes:

> extern struct passwd *getpwuid (uid_t uid);
> struct passwd * getpwuid (uid) uid_t uid; {}

> Is my [ supposedly ] ANSI-compliant compiler free to warn
> me that getpwuid() has been redefined?

A conforming compiler is always free to produce warnings about
anything.  It MUST produce at least one diagnostic (error or warning)
for a program which violates a syntax rule or a constraint.  It
MUST NOT produce a [fatal] error on a strictly conforming program.

> Is this just a warning or should this be a fatal error?

A fatal error is never required.  If the compiler thinks it can
make sense of what you gave it, it is always free to generate
whatever code it can, as long as it satisfies the requirement to
produce a diagnostic if a syntax rule or constraint has been broken.

The legality of your program, that is, whether it is strictly
conforming, depends on how uid_t is defined.  If uid_t is
defined as int, for example, your program is legal, but warnings (as
always) are allowed.  If uid_t is defined as short, your program is
illegal, and a diagnostic (error or warning) is required to be produced.
The constraint being violated is in 3.5:  "All declarations in the
same scope that refer to the same object or function shall specify
compatible types."

> The relevant section is [ I think, dyslexia not withstanding ]
> 3.7.1.  

More relevant, I think, is 3.5.4.3.  "For two function types
to be compatible, both shall specify compatible return types. ...
If one type has a parameter type list and the other type is
specified by a function definition that contains a (possibly empty)
identifier list, both shall agree in the number of parameters, and
the type of each prototype parameter shall be compatible with the
type that results from the application of the default argument
promotions to the type of the corresponding identifier."

In your example, this requires that the default argument promotions,
when applied to the type uid_t, must result in a type that is
compatible with uid_t.  

The obvious solution is to change your program to use a function
prototype in the function definition as well as in the original
declaration:
   struct passwd * getpwuid (uid_t uid) {}

> Relevant draft information - this is the January 1989 draft.

That's new to me!  Where does one get a copy of the January 1989 draft?
(I am quoting from the December 7, 1988, draft.)

Walter Murray
Not speaking for X3J11
----------------------



More information about the Comp.std.c mailing list