Announcement

Collapse
No announcement yet.

Are C Enumerations always Long data type

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Are C Enumerations always Long data type

    Hello community,

    the following listing shows a small C code with an enumeration, an assignment of value in the main procedure and the disassembled code.

    Code:
    //-Begin----------------------------------------------------------------
     
      typedef enum _RFCTYPE
      {
        RFCTYPE_CHAR   = 0,
        RFCTYPE_DATE   = 1,
        RFCTYPE_BCD    = 2,
        RFCTYPE_TIME   = 3,
        RFCTYPE_BYTE   = 4,
        RFCTYPE_TABLE  = 5,
        RFCTYPE_NUM    = 6,
        RFCTYPE_FLOAT  = 7,
        RFCTYPE_INT    = 8,
        RFCTYPE_INT2   = 9,
        RFCTYPE_INT1   = 10,
        RFCTYPE_NULL   = 255
      }RFCTYPE;
     
      int main (void) {
        RFCTYPE i = RFCTYPE_NULL;
      }
     
    /*
    55                      push ebp
    89E5                    mov ebp, esp
    81EC04000000            sub esp, 00000004
    90                      nop
    B8FF000000              mov eax, 000000FF
    8945FC                  mov dword[ebp-04], eax
    C9                      leave
    C3                      ret
    */
     
    //-End------------------------------------------------------------------
    Are this kind of enumerations always from the data type LONG resp. DWORD? Or is it possible that they may be of a different data type?

    Thanks for tips.

    Cheers
    Stefan
    Visit my private homepage and my commercial homepage
    Meet me at XING or Google+

  • #2
    Originally posted by Stefan Schnell View Post
    Are this kind of enumerations always from the data type LONG resp. DWORD? Or is it possible that they may be of a different data type?
    The C ANSI Standard requires enumerations to be of type INTEGER.
    The world is strange and wonderful.*
    I reserve the right to be horrifically wrong.
    Please maintain a safe following distance.
    *wonderful sold separately.

    Comment


    • #3
      Enumerations don't have a "data type"; they are representations of a value

      How you store any value - the 'data type' in your compiler or interpreter - is a function of that compiler.

      Consider this line of PowerBASIC code:
      Code:
      %EQUATE = 2
      The value two could be stored in a byte, a 16, 32, or 64-bit integer, or in an IEEE float.

      So how is it stored? Yes, the answer is in the help file under "equates."'

      Can you, the programmer, change how a value is stored? Yes, and that's explained in the same 'equate' section of the help ... but it is easier to show:
      Code:
        A! =  2
        B# = 2 
        C& = 2 
       ...
      How is the value "two" stored - that is, what is its data type - in this program?

      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        Enumerations don't have a "data type"; they are representations of a value

        How you store any value - the 'data type' in your compiler or interpreter - is a function of that compiler.
        And in a C compiler, the ANSI Standard says that you can store an INTEGER.
        If the value exceeds that of the type allowed, the result is undefined.
        The world is strange and wonderful.*
        I reserve the right to be horrifically wrong.
        Please maintain a safe following distance.
        *wonderful sold separately.

        Comment


        • #5
          Hello Kurt and Michael,

          thanks for your replies.

          Cheers
          Stefan
          Visit my private homepage and my commercial homepage
          Meet me at XING or Google+

          Comment


          • #6
            Originally posted by Kurt Kuzba View Post
            And in a C compiler, the ANSI Standard says that you can store an INTEGER.
            er, no.

            The ANSI standard for C does not define an INTEGER but does define an int, having the storage defined for an int by the compiler, generally 32 bits wide in 32-bit architectures. Note: PowerBASIC's INTEGER datatype is 16 bits wide.

            There are many references on the web, here's one from M$: http://msdn.microsoft.com/en-us/library/whbyts4t.aspx

            Comment


            • #7
              Just re-read the first post and the OP mentions "small C". Did he mean "Small C"? "Small C" is an ANSI C subset for 8-bit machines. I think that this compiler's int datatype is 16 bits wide.

              And in "Tiny C" it's 8 bits, as you may have guessed. *** Added *** oh, cancel that statement. That was in 1988. Another Tiny C has sprung up in the intervening years, for X86. I doubt if it uses 8-bit ints! Here's a link: http://bellard.org/tcc/
              Last edited by Chris Holbrook; 7 Aug 2013, 03:05 AM. Reason: ***

              Comment


              • #8
                Chris' point - that 'int' means something specific to the 'c' language - is a good one.

                Not that it's any different from saying 'CUR' or LONG mean something specific to the PowerBASIC dialect of the BASIC language.

                Just something to think about when wondering why your mindless verb-for-verb, function-for-function, statement-for-statement conversion from one source code language to another "don't work."
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment

                Working...
                X