home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / gcc / bug / 3243 < prev    next >
Encoding:
Text File  |  1993-01-25  |  3.3 KB  |  83 lines

  1. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!midget.saar.DE!bof
  2. From: bof@midget.saar.DE (Patrick Schaaf)
  3. Newsgroups: gnu.gcc.bug
  4. Subject: Re: Prototype handling bug(?) in 2.3.3
  5. Date: 25 Jan 1993 20:54:17 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 69
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-gcc@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <m0nGJYi-0003iPC@midget.saar.de>
  12. References: bof@midget.saar.DE (Patrick Schaaf)
  13.  
  14. In reply to Jason Merrills message on "Re: Prototype handling bug(?) in 2.3.3"
  15. >Suppose you have
  16. >void foobar();
  17. >short a, b;
  18. >foobar(a,b);
  19. >void foobar(c,d)
  20. >    short c,d;
  21. >{
  22. >}
  23. >
  24. >Then are c and d promoted to int as well?  Just curious.
  25.  
  26. Because foobar is declared and defined without a prototype, the parameters are
  27. always passed as ints. The
  28.     short c,d;
  29. instructs the compiler to _interpret_ the two arguments as shorts (i.e.
  30. retrieve the correct part of them according to the byte sex of the machine
  31. it compiles for).
  32.  
  33. >I would agree with that.  Unfortunately, the compiler message is an error,
  34. >not a warning, so I am forced to comment out the first prototype somehow.
  35. >Unfortunately, it is in one of the system headers, which makes that an
  36. >annoying task.
  37.  
  38. _Especially_ in this case, GnuC is helping you by making this an error.
  39. The non-prototype declaration in the system include file tells you that
  40. your getpwuid _expects_ to be called with an int on the stack, regardless
  41. of how many bits of it it really uses. Now, you introduce the prototype
  42. struct passwd *getpwuid(u_short uid);
  43. which, if treated as a warning, gives GnuC two possibilities to proceed:
  44.   - ignore your own prototype, and pass the parameters as an int.
  45.     this would work in your case, but it wouldn't work if getpwuid were
  46.     your own function, defined in some other module with a prototype
  47.     argument list. In this case you would prefer
  48.   - use your own prototype, and ignore the non-prototype declaration in
  49.     the system header file. This, of course, will call the system library
  50.     function with wrong arguments.
  51. The compiler can't know how the function was defined, so it can't guess
  52. what the Right Thing (tm) is in general. It might do this if the function
  53. in question were in the same compilation unit, but it is not required to.
  54.  
  55. Two more comments:
  56.   - if your manpage states that getpwuid has an int as the parameter, your
  57.     prototype is simply wrong.
  58.   - modern Unix (Posix) systems define a type "uid_t" as the parameter
  59.     of getpwuid() and friends. If you attempt to provide prototypes for
  60.     system library functions for some portable software distribution,
  61.     use "uid_t" in your prototypes, and provide a proper definition of
  62.     uid_t for any target machine that doesn't already know it.
  63.  
  64. Just in case you are confused by the use of "defined" and "declared"
  65. above, they are ANSI terms. A definition defines the exact behaviour of a
  66. function, i.e. the implementation:
  67. int foobar(short bla)
  68. { dosomething(bla); }
  69. A declaration declares how a function is called, i.e. both prototyped and
  70. non-prototyped "interface definitions" for a function are declarations:
  71. int foobar();
  72. int foobar(short);
  73. This meaning is consistently used in the standard for variables, too.
  74.  
  75.  
  76.     Patrick
  77.  
  78.  
  79. -- 
  80. progress and die. this is just the way the world goes round.
  81. a comment by patrick schaaf, saarbruecken, germany.
  82.  
  83.