Thread: enum with cc/gcc

  1. #1
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42

    enum with cc/gcc

    Hello,
    I've in my program enumerations defined in this way:
    Code:
    enum ERRORS {FALSE=-1,SUCCESS = 0, TRUE};
    enum PTYPE  {BACKGROUND = 0, NON, REDIRECT_RIGHT, REDIRECT_LEFT, PIPE};
    but it does not compile with cc nor with gcc ?
    it says syntax error on first enum

    please help

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Spread them over several lines and find out where the syntax error really is.

    My guess is that FALSE and/or TRUE are macros and get replaced by something else.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42
    you were right, FALSE and/or TRUE are macros in some header file.
    Thank you CornedBee

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    enum ERRORS {FILE_NOT_FOUND=-1,FALSE = 0, TRUE};

    FTFY
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    If you're really stuck in future, trying to figure out odd error messages like this, then consider

    gcc -E prog.c > prog.i

    prog.i will be the result after ALL the pre-processor includes and #defines have been expanded.
    It's a large file (usually), and what you want is usually at the end.

    But you would see things like
    Code:
    enum ERRORS {0=-1,SUCCESS = 0, 1};
    which would clearly indicate that the pre-processor had messed up your code.

    By convention, everything which is all UPPERCASE should be regarded as being a macro (there are a few standard exceptions though). Avoiding all uppercase names for all your symbols (which are not macros you know about) is one way of avoiding falling into this particular trap.
    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.

  6. #6
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42
    Thanks Salem for this helpful advice

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  2. enum [tag] [: type] Is this non-standard?
    By HyperShadow in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 10:29 PM
  3. enum switchcase and windows message q
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 01:16 PM
  4. Conflicting enum issue
    By 7force in forum C Programming
    Replies: 1
    Last Post: 07-05-2006, 03:51 AM
  5. Switch case and enum help
    By SomeCrazyGuy in forum C++ Programming
    Replies: 9
    Last Post: 04-21-2005, 08:53 PM