Thread: enums and strict aliasing rule

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229

    enums and strict aliasing rule

    Does accessing enums through int pointers break the strict aliasing rule? Or are enums treated as ints?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Incompatibilities Between ISO C and ISO C++
    enums might not even be the same SIZE as an int, so no, stop thinking about whatever it is you're trying to do.

    Unless you're posting on C++ just to keep things interesting...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Ah! I wasn't aware of that.

    Thanks

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    I believe that in C++0x you can do this:
    Code:
    enum SomeName : int {
    To force it to be of integer size. Though I'm not 100% sure about this and have no time to verify atm.

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by EVOEx View Post
    I believe that in C++0x you can do this:
    Code:
    enum SomeName : int {
    To force it to be of integer size. Though I'm not 100% sure about this and have no time to verify atm.
    correct

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Why would you want to acess an enum through an int pointer?

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    It's a function that is overloaded for a bunch of basic types, but not enum types, so I thought maybe I can just use the int version.

    Ended up doing something completely different.

Popular pages Recent additions subscribe to a feed