0

I have a C++ declaration:

enum SETTINGS:UINT32
{
     a=1,
     b=2,
};
  1. what is the meaning of :UINT32?
  2. how can I swich this declaration to linux?
dubila
  • 1,099
  • 2
  • 10
  • 11

3 Answers3

4

Its part of the new C++0x way of declaring enums

enum <EnumTypeName> [: <Optinal-Type>] { <ValueList> };

By default an enum is represented by an integer.
The new syntax allows you to optionally define the type used to represent the enum

In this case it indicates that the enum underlying representation should be of type UINT32. What this means will depend on what the macro UINT32 has been defined to be. But it is probably an integer of at least 32 bits and is unsigned. :-)

See Bjornes description of the new enum stuff:
http://www2.research.att.com/~bs/C++0xFAQ.html#enum

Martin York
  • 257,169
  • 86
  • 333
  • 562
  • There is no default for the enum in the standard, this is specically why this new format was introduced. It allows you to forward declare enums's, which wasn't possible before since the whole enum would be needed to determine the size of it. (I don't doubt however that int is almost always used) – edA-qa mort-ora-y Nov 18 '10 at 09:21
  • @edA-qa mort-ora-y: Actually the standard explicitly states that enum will be represented by an integer type (and their are some special rules that nobody but the compiler writer cares about). Though the default is implementation defined which integer type. See section 7.2 (I was reading the Draft immediately following the C++03 standard but I doubt it has changed). – Martin York Nov 18 '10 at 10:41
  • I meant that it won't necessarily use the "int" type, it will simply use one of the integer types. That is it can choose whichever size it wants for the enum based on its values: the reason why it can't be forward declared. – edA-qa mort-ora-y Nov 18 '10 at 10:47
  • "An integer" is not only the default representation, but it *is* the underlying type of an enumeration in all cases. So why do you write "By default"? – Johannes Schaub - litb Nov 20 '10 at 04:11
1

Here, the :UINT32 syntax specifies the underlying enum type. However, this is not standard C++ (at least, not standard C++03) but a Visual Studio extension : g++ will probably reject it, and you should too.

EDIT As pointed in the comments by Martin York, g++ supports this syntax since version 4.4, so I guess the only issue for a Linux portage would be UINT32 being non standard.

icecrime
  • 74,451
  • 13
  • 99
  • 111
-1

u = unsigned int = integer 32 = 32 bit

read this : "Uint32", "int16" and the like; are they standard c++?

Community
  • 1
  • 1
Bourne
  • 10,094
  • 5
  • 24
  • 51
  • if you only took some time reading the post, your head would understand that it is as related to the post as your comment to the question owner is. Of course it is a macro. – Bourne Nov 18 '10 at 09:12
  • i guess the question here was, what does `enum_type [: optional-type]`, means, and not about uints and ints. – sud03r Nov 18 '10 at 09:18