locked
Setting for enum as an 8 bit instead of 32 bit RRS feed

  • Question

  • I am using VC++ for embedded application where I want enum as an 8 bit instead of 32 bit default to save my memory. Is there any setting to do so in visual studio?

    Please let me know if anybody is having idea about the same as this is very much important for me.

    Thanks in advance 

    • Moved by Chao Kuo Monday, September 27, 2010 10:59 AM Post here VC http://social.msdn.microsoft.com/Forums/en/category/visualc/ (From:Visual Basic General)
    Wednesday, September 22, 2010 5:59 AM

All replies

  • Why not try this in a VC++ forum instead of a VB forum?
    Success
    Cor
    • Proposed as answer by Rudedog2 Wednesday, September 22, 2010 4:23 PM
    Wednesday, September 22, 2010 6:57 AM
  • Please post your question to one of the Visual C++ forums, or perhaps a moderator can move it there:

    http://social.msdn.microsoft.com/Forums/en/category/visualc/

     


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, September 22, 2010 12:35 PM
  • Hi Pravin F,

    Here is how it would be in VB.Net to limit the size of the value in an ENUM.

    BYTE = an unsigned 8 bit value.

    SBYTE = a signed 8 bit value.

    ( I guess the same keywords are used in Visual C++ and Visual C#  , but don't take my word for it ).

     

    Public Class Form1
    
      Public Enum ExampleEnum1 As Byte
        one = 1
        two55 = 255
      End Enum
    
      Public Enum ExampleEnum2 As SByte
        minus128 = -128
        one = 1
        one27 = 127
      End Enum
    
    End Class
    
    
    'An ENUM may be defined outside of a CLASS too.>>>>
    
    Public Enum ExampleEnum3 As SByte
      minus128 = -128
      one = 1
      one27 = 127
    End Enum
    
    Public Enum ExampleEnum4 As Byte
      zero = 0
      one = 1
      two55 = 255
    End Enum
    



    Regards,

    John

    www.johnaoliver.com
    Wednesday, September 22, 2010 2:56 PM
  • Enums are integral types only in C/C++...it is a basic tenant of the language. Constants are a way to use BYTES as particular values in C/C++
    Wednesday, September 22, 2010 3:21 PM
  • Enums are integral types only in C/C++...it is a basic tenant of the language. Constants are a way to use BYTES as particular values in C/C++


    Hi jinzai,

    Do you mean "integral " as "built-in" or as based on whole number i.e. INTEGER values only?

    Don't forgot that the mathematical meaning of an INTEGER is a whole number that is positive or negative.

    http://www.thefreedictionary.com/integer

    If you mean integer only then the same applies in VB.Net.    ;-)

     



    Regards,

    John

    www.johnaoliver.com
    Wednesday, September 22, 2010 3:39 PM
  • Underlying Type of an Enum in C++

    Mark the best replies as answers. "Fooling computers since 1971."

    http://rudedog2.spaces.live.com/default.aspx

    Wednesday, September 22, 2010 4:23 PM
  • I was not going to post in here for that very reason. When you use an enum in C++ CLR, you can use whatever underlying scalar type you want, but...an enum in C is based on an integer (type int), and nothing else.

    The OP said VC++, and I should have simply referred them there.

    • Edited by jinzai Wednesday, September 22, 2010 5:24 PM try to clarify
    Wednesday, September 22, 2010 5:23 PM