home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!midget.saar.DE!bof
- From: bof@midget.saar.DE (Patrick Schaaf)
- Newsgroups: gnu.gcc.bug
- Subject: Re: Prototype handling bug(?) in 2.3.3
- Date: 25 Jan 1993 20:54:17 -0500
- Organization: GNUs Not Usenet
- Lines: 69
- Sender: daemon@cis.ohio-state.edu
- Approved: bug-gcc@prep.ai.mit.edu
- Distribution: gnu
- Message-ID: <m0nGJYi-0003iPC@midget.saar.de>
- References: bof@midget.saar.DE (Patrick Schaaf)
-
- In reply to Jason Merrills message on "Re: Prototype handling bug(?) in 2.3.3"
- >Suppose you have
- >void foobar();
- >short a, b;
- >foobar(a,b);
- >void foobar(c,d)
- > short c,d;
- >{
- >}
- >
- >Then are c and d promoted to int as well? Just curious.
-
- Because foobar is declared and defined without a prototype, the parameters are
- always passed as ints. The
- short c,d;
- instructs the compiler to _interpret_ the two arguments as shorts (i.e.
- retrieve the correct part of them according to the byte sex of the machine
- it compiles for).
-
- >I would agree with that. Unfortunately, the compiler message is an error,
- >not a warning, so I am forced to comment out the first prototype somehow.
- >Unfortunately, it is in one of the system headers, which makes that an
- >annoying task.
-
- _Especially_ in this case, GnuC is helping you by making this an error.
- The non-prototype declaration in the system include file tells you that
- your getpwuid _expects_ to be called with an int on the stack, regardless
- of how many bits of it it really uses. Now, you introduce the prototype
- struct passwd *getpwuid(u_short uid);
- which, if treated as a warning, gives GnuC two possibilities to proceed:
- - ignore your own prototype, and pass the parameters as an int.
- this would work in your case, but it wouldn't work if getpwuid were
- your own function, defined in some other module with a prototype
- argument list. In this case you would prefer
- - use your own prototype, and ignore the non-prototype declaration in
- the system header file. This, of course, will call the system library
- function with wrong arguments.
- The compiler can't know how the function was defined, so it can't guess
- what the Right Thing (tm) is in general. It might do this if the function
- in question were in the same compilation unit, but it is not required to.
-
- Two more comments:
- - if your manpage states that getpwuid has an int as the parameter, your
- prototype is simply wrong.
- - modern Unix (Posix) systems define a type "uid_t" as the parameter
- of getpwuid() and friends. If you attempt to provide prototypes for
- system library functions for some portable software distribution,
- use "uid_t" in your prototypes, and provide a proper definition of
- uid_t for any target machine that doesn't already know it.
-
- Just in case you are confused by the use of "defined" and "declared"
- above, they are ANSI terms. A definition defines the exact behaviour of a
- function, i.e. the implementation:
- int foobar(short bla)
- { dosomething(bla); }
- A declaration declares how a function is called, i.e. both prototyped and
- non-prototyped "interface definitions" for a function are declarations:
- int foobar();
- int foobar(short);
- This meaning is consistently used in the standard for variables, too.
-
-
- Patrick
-
-
- --
- progress and die. this is just the way the world goes round.
- a comment by patrick schaaf, saarbruecken, germany.
-
-