Re: Specifying "enum" data size
Re: Specifying "enum" data size
- Subject: Re: Specifying "enum" data size
- From: Mark Wagner <email@hidden>
- Date: Mon, 26 Sep 2005 10:29:20 -0700
On 9/24/05, Andreas Grosam <email@hidden> wrote:
>
> On 24.09.2005, at 02:17, Chris Espinosa wrote:
>
> > On Sep 23, 2005, at 5:04 PM, Mark Wagner wrote:
> >
> >> How do I specify the size of an "enum" value? I've got a program that
> >> links to a number of static libraries. In one of them, an "enum" for
> >> the typedef'd "BoolEnum" type is one bit, while in another, it's 32
> >> bits. Needless to say, this causes problems when passing structs
> >> containing BoolEnums back and forth.
> >>
> >> Does GCC recognize the "#pragma enumsalwaysint" pragma? Might the
> >> presence of this in some of the source files be causing problems?
> >>
> >> I'm using XCode 1.5 and GCC 3.3, and I'm writing in C.
> >
> > The only control available is -fshort-enums ("Short Enumeration
> > Constants") which you can apply on a target or on a single file.
> > There's no pragma to make this apply only to specific enums within a
> > file. This will make enums as small as possible for the range of
> > enums given.
> >
> > Notice that Mac OS X frameworks often declare structs that contain
> > enumerated values, so changing the size of enums might make your code
> > unable to call Mac OS X system functions.
> Are you sure? I thought, enums were only be used to declare constants
> and never be used as types. Thus, enums do not have any effect on the
> layout or sizeof of structs.
>
> Otherwise, in the C language this would be a very fragile usage. In C,
> i would never ever use enums as types in interfaces since the size of
> the enum type is compiler "implementation defined", may depend on
> optimization flags, architecture, etc.
>
> Note, that binary compatibility (here the size of enums) may only be
> guaranteed when you use the same C compiler.
> I also wouldn't use the switch for enums used in interfaces. The
> documentation says this:
> "Warning: the -fshort-enums switch causes GCC to generate code that is
> not binary compatible with code generated without that switch. Use it
> to conform to a non-default application binary interface. "
>
>
>
> In your case, it looks like, that your static library has been compiled
> with this switch on, or with another compiler, or other compiler flags
> changing the size of the enum - thus it is not binary compatible
> anymore.
>
> Well, to workaround your problem, re-compile the static libraries using
> *your* compiler (gcc 3.3) in order to get ABI compatibility.
Everything was compiled using gcc 3.3, with the -fshort-enums switch
disabled. That's why I'm asking about "#pragma enumsalwaysint" --
it's the only thing I can think of that would be causing the problems.
For the Apple ABI, how long should an enum type with two possible
values be, anyway? Is the library that thinks it's 32 bits correct,
or is the library that thinks it's one bit correct? Or are they both
wrong?
Thanks,
Mark Wagner
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden