enums and strict aliasing rule

This is a discussion on enums and strict aliasing rule within the C++ Programming forums, part of the General Programming Boards category; Does accessing enums through int pointers break the strict aliasing rule? Or are enums treated as ints?...

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

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    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
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Why would you want to acess an enum through an int pointer?

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21