home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / std / c / 2523 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  2.1 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!ucbvax!jit081.enet.dec.com!diamond
  2. From: diamond@jit081.enet.dec.com (27-Aug-1992 1743)
  3. Newsgroups: comp.std.c
  4. Subject: Re: space optimization involving enum
  5. Message-ID: <9208270847.AA02449@enet-gw.pa.dec.com>
  6. Date: 27 Aug 92 08:47:39 GMT
  7. Sender: usenet@ucbvax.BERKELEY.EDU
  8. Lines: 38
  9.  
  10. In article <19920826.124331.137@almaden.ibm.com> dmm@vnet.ibm.com (dave) writes:
  11. >In <1992Aug26.184220.8236@taumet.com> Steve Clamage writes:
  12. [In prototyping functions that are defined without prototypes]
  13. >> If enums are smaller than ints, avoid those too.
  14. >
  15. >That means that given
  16. >  enum c { red, green, blue };
  17. >  int f( x ) enum c x; { }
  18. >there is no strictly-conforming way to write a parameter-list prototype
  19. >for the function f.
  20.  
  21. True.  If you want to use enums but omit prototypes in function definitions,
  22. and if you want to remain portable, then you have to omit prototypes when
  23. calling those functions as well.
  24.  
  25. However, if you are willing to define your functions as taking ints instead
  26. of enums, then (usually) you can add prototypes in whichever portions of your
  27. program that you wish, and not have to change any of the actual calls, and
  28. maintain portability.  The reason is that the values of enum constants still
  29. have to fit in ints, i.e. portable programs could never have defined anything
  30. like  enum c { red = 32768 };  in the first place.
  31.  
  32. >  int f( int );
  33. >would be right if  enum c  were of short or char size.  If  enum c  were
  34. >of int or long size, then
  35. >  int f( enum c );
  36. >would be the prototype, right?
  37.  
  38. Well, if  enum c  were of int size then  int f(int);  would still have been
  39. good enough too.  You get in trouble with long though as you said -- and
  40. possibly also if the standard's citations of "implementation-defined"
  41. integral types are allowed to include implementation-provided extensions to
  42. the standard integral types (an unsolved question).
  43. --
  44. Norman Diamond       diamond@jit081.enet.dec.com
  45. If this were the company's opinion, I wouldn't be allowed to post it.
  46. "Yeah -- bad wiring.  That was probably it.  Very bad."
  47. wq
  48.