Enum type safety in NPNGetValue

Eirik Byrkjeflot Anonsen eirik at opera.com
Thu Jun 3 23:13:03 PDT 2010


Karl Tomlinson <karlt at karlt.net> writes:

>> enum Foo {
>>  Bar = 1,
>>  FooBar = 2,
>>
>>  Foo_ForceInt32 = 0xffffffff
>> };
>
> That will make the underlying C++ type unsigned int on systems
> with 32-bit ints.

Or signed, but with a bigger integral type than 32 bits.

> (Signed int may still be used on systems with 64-bit ints).
>
> But in C, are all enums of type (signed) int?

No.

> Not sure that matters too much, given that the sizes will be the same.
>
> I like the suggestion of using explicitly sized (signed or
> unsigned) integers.  It avoids C/C++ differences.
>
> Though, I would be interested to hear if there is a C++ compiler
> that breaks C compatibility by using enum types smaller than int.

Yes, gcc and realview comes to mind.  I assume most modern compilers do
this.  However, this doesn't break C compatibility, since the C89
specification says that enums are integral types at least large enough
to hold all its declared values.  So I assume most modern C compilers do
this too.

eirik


More information about the plugin-futures mailing list