🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1222

Re: space optimization involving enum

#1222
From: 27-Aug-1992 1743
Date: Thu, 27 Aug 1992 08:47
38 lines
2171 bytes
In article <19920826.124331.137@almaden.ibm.com> dmm@vnet.ibm.com (dave) writes:
>In <1992Aug26.184220.8236@taumet.com> Steve Clamage writes:
[In prototyping functions that are defined without prototypes]
>> If enums are smaller than ints, avoid those too.
>
>That means that given
>  enum c { red, green, blue };
>  int f( x ) enum c x; { }
>there is no strictly-conforming way to write a parameter-list prototype
>for the function f.

True.  If you want to use enums but omit prototypes in function definitions,
and if you want to remain portable, then you have to omit prototypes when
calling those functions as well.

However, if you are willing to define your functions as taking ints instead
of enums, then (usually) you can add prototypes in whichever portions of your
program that you wish, and not have to change any of the actual calls, and
maintain portability.  The reason is that the values of enum constants still
have to fit in ints, i.e. portable programs could never have defined anything
like  enum c { red = 32768 };  in the first place.

>  int f( int );
>would be right if  enum c  were of short or char size.  If  enum c  were
>of int or long size, then
>  int f( enum c );
>would be the prototype, right?

Well, if  enum c  were of int size then  int f(int);  would still have been
good enough too.  You get in trouble with long though as you said -- and
possibly also if the standard's citations of "implementation-defined"
integral types are allowed to include implementation-provided extensions to
the standard integral types (an unsolved question).
--
Norman Diamond       diamond@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"Yeah -- bad wiring.  That was probably it.  Very bad."
wq
Technical Details
Message-ID: <9208270847.AA02449@enet-gw.pa.dec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!ucbvax!jit081.enet.dec.com!diamond

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!ucbvax!jit081.enet.dec.com!diamond
From: diamond@jit081.enet.dec.com (27-Aug-1992 1743)
Newsgroups: comp.std.c
Subject: Re: space optimization involving enum
Message-ID: <9208270847.AA02449@enet-gw.pa.dec.com>
Date: 27 Aug 92 08:47:39 GMT
Sender: usenet@ucbvax.BERKELEY.EDU
Lines: 38