Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Size of 'enum'

Size of 'enum'

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ryan B
    wrote on last edited by
    #1

    I know that the size of enum in VC++ is by default "integral". So the following structure is 4 bytes (or sizeof(int)). I also know that the size will scale based upon the value of said enumeration. However, I need my enum to be 'short' in order to read some binary data into a much larger structure that contains many of these enums? How can I cahnge the size?

    typedef enum _ALARM_TYPE
    {
    LATCHING = 0,
    SELF_CLEARING
    } ALARM_TYPE;

    Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

    R 1 Reply Last reply
    0
    • R Ryan B

      I know that the size of enum in VC++ is by default "integral". So the following structure is 4 bytes (or sizeof(int)). I also know that the size will scale based upon the value of said enumeration. However, I need my enum to be 'short' in order to read some binary data into a much larger structure that contains many of these enums? How can I cahnge the size?

      typedef enum _ALARM_TYPE
      {
      LATCHING = 0,
      SELF_CLEARING
      } ALARM_TYPE;

      Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

      R Offline
      R Offline
      Ryan B
      wrote on last edited by
      #2

      Got It, Nevermind.... #pragma enum(2) Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

      R 1 Reply Last reply
      0
      • R Ryan B

        Got It, Nevermind.... #pragma enum(2) Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

        R Offline
        R Offline
        Ryan B
        wrote on last edited by
        #3

        nope, I was wrong.. still looking that was under AIX Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

        R 1 Reply Last reply
        0
        • R Ryan B

          nope, I was wrong.. still looking that was under AIX Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

          R Offline
          R Offline
          Ryan B
          wrote on last edited by
          #4

          for everyones benefit I am going to post that I have found you cannot change the size of enum under VC++. In some other environments you can. Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

          A 1 Reply Last reply
          0
          • R Ryan B

            for everyones benefit I am going to post that I have found you cannot change the size of enum under VC++. In some other environments you can. Ryan Baillargeon Software Specialist Fuel Cell Technologies Inc.

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Can you do the conversion yourself? By that I mean, if you want the enum to fit into a short then convert it to a short and read/write that. You may need to do some funky casting and/or memcpy'ing, but the effects will be the same and will work on other compilers too

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups