home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / std / c / 2471 < prev    next >
Encoding:
Text File  |  1992-08-14  |  3.8 KB  |  81 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!gatech!darwin.sura.net!jvnc.net!yale.edu!think.com!paperboy.osf.org!meissner
  3. From: meissner@osf.org (Michael Meissner)
  4. Subject: Re: mixing prototyping and non-prototyping
  5. In-Reply-To: spuler@coral.cs.jcu.edu.au's message of 13 Aug 92 23:42:25 GMT
  6. Message-ID: <MEISSNER.92Aug14143649@tiktok.osf.org>
  7. Sender: news@osf.org (USENET News System)
  8. Organization: Open Software Foundation
  9. References: <spuler.713749345@coral.cs.jcu.edu.au>
  10. Date: 14 Aug 92 14:36:49
  11. Lines: 68
  12.  
  13. In article <spuler.713749345@coral.cs.jcu.edu.au> spuler@coral.cs.jcu.edu.au (David Spuler) writes:
  14.  
  15. | What are the rules regarding mixing old-style and new-style functions in C
  16. | programs?  Specifically, what mixtures must a compiler support,and which can
  17. | be legally allowed to bomb?
  18. | Can a prototyped function be legally called without a prototype in scope?  
  19. | My understanding was that this sort of mixing was allowed except for varargs
  20. | functions, or prototyped functions with char/float/short parameters, but I
  21. | was recently told I was wrong.  Could someone clear it up for me.
  22.  
  23. You are right.  In the ANSI committee, this rule is refered to as the
  24. Miranda Rule, after the Miranda case in the US legal system.  The
  25. Miranda part comes from:
  26.  
  27.     You have the right to a prototype.  If you cannot afford a
  28.     prototype, one will be appointed to you by the compilation
  29.     system.
  30.  
  31. Section 3.3.2.2 of the standard reads in part:
  32.  
  33.        If the expression that denotes the called function has a
  34.     type that does not include a prototype, the integral
  35.     promotions are perfomed on each argument and arguments that
  36.     have type 'float' are promoted to 'double'.  These are called
  37.     the 'default argument promotions'.  If the number of arguments
  38.     does not agree with the number of parameters, the behavior is
  39.     undefined.  If the function is defined with a type that does
  40.     not include a prototype, and the types of the argument after
  41.     promotion are not compatible with those of the parameters
  42.     after promotion, the behavior is undefine.  If the function is
  43.     define with a type that includes a prototype, and the types of
  44.     the arguments after promotion are not compatible with the
  45.     types of the parameters, or if the prototype ends with an
  46.     ellipsis (, ...), the behavior is undefined.
  47.  
  48. | Can a non-prototyped function be called with a prototype in scope?
  49. | I assume not.
  50.  
  51. Actually, yes, as long as the function does not have char/short/float
  52. arguments, or a variable argument list.  In fact, this is the typical
  53. way code is prototyped, by first changing the headers to have
  54. prototypes, and then sometime in the future, going back and changing
  55. the function definitions.  This way is especially useful when you have
  56. some ANSI compilers you are porting to and some K&R classic compilers.
  57. Only the headers (and the varadic functions) need __STDC__ ifdefs.
  58.  
  59. Section 3.5.4.3 of the standard reads in part (talking about function
  60. types being compatible):
  61.  
  62.     ... If one type has a parameter type list and the other type
  63.     is specified by a function definition that contains a
  64.     (possibly empty) identifier list, both shall agree in the
  65.     number of parameters, and the type of each prototype parameter
  66.     shall be compatible with the type that results from the
  67.     application of the default argument promotions to the type of
  68.     the corresponding identifier.  (For each parameter declared
  69.     with function or array type, its type for these comparisons is
  70.     the one that results from converion to a pointer type, as in
  71.     section 3.7.1.  For each parameter declared with qualified
  72.     type, its type for these comparisons is the unqualified
  73.     version of its declared type.)
  74. --
  75. Michael Meissner    email: meissner@osf.org        phone: 617-621-8861
  76. Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
  77.  
  78. You are in a twisty little passage of standards, all conflicting.
  79.