Thread: enum with assignments is standard?

  1. #1
    Alessio Stella
    Join Date
    May 2008
    Italy, Bologna

    enum with assignments is standard?

    just an example:
    typedef enum {
    	TimeOut = 0x0938,
    	CC = 0x0A00
    } Type_RegisterAddress;
    the previous use of enum with assignment is ANSI C or it is something working only for some C compilers?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    It's valid in C99; I don't remember whether it was valid in C89.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Yes you can do that.
    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.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Yes, that is ANSI standard C89.
    An enumeration type declares a set of named constants, with type int. An enumerator with = defines enumeration constant. If the first enumerator has no =, its enumeration constant is 0. Each enumerator with no = defines an enumeration constant, by adding 1 to the previous one.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Standard efficiency
    By Jorl17 in forum C Programming
    Replies: 3
    Last Post: 06-18-2009, 11:48 AM
  2. Odd enum error...
    By tjpanda in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2008, 03:08 AM
  3. accessing enum members
    By stanlvw in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2008, 02:58 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  5. standard language, standard compiler?
    By doubleanti in forum A Brief History of
    Replies: 8
    Last Post: 09-03-2001, 04:21 AM