Thread: enum problem

  1. #1
    Registered User
    Join Date
    Aug 2023
    Posts
    45

    Exclamation enum problem

    In the attached zip file there are 2 enums: TInstruction and TRegister. My compiler doesn't like TInstruction enum. Attached error.png shows the errors being complained about. I cannot see any difference between the 2 enums except their lists! I'm at a loss on this problem. I sure hope this is something simple here that I am missing.
    maxcy/wt1v
    Attached Images Attached Images enum problem-error-png 
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Aug 2023
    Posts
    45

    Red face

    Quote Originally Posted by maxcy View Post
    In the attached zip file there are 2 enums: TInstruction and TRegister. My compiler doesn't like TInstruction enum. Attached error.png shows the errors being complained about. I cannot see any difference between the 2 enums except their lists! I'm at a loss on this problem. I sure hope this is something simple here that I am missing.
    maxcy/wt1v
    I did some experimenting in the TInstruction enum: changed and, or, xor to tand, tor, txor since that was where most of the compiler complaints came from. Enum is no longer a problem, but the rest of the code that relied on and, or, xor are now giving complaints as expected!! So these 3 words are reserved by the compiler and no one gets to use them in enums! How do I get around this quagmire?
    maxcy/wt1v

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    > and, or, xor
    These are actual keywords in C++.

    You need to make a different name.
    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
    Registered User
    Join Date
    Aug 2023
    Posts
    45
    That doesn't make any sense! A compiler needs to make tokens for all reserved words not just these 3! I can't imagine writing a compiler and not being able to write tokens for any reserved word! I think that while writing a C++ compiler, one would need to include these keywords. I always thought that what I put into an enum list has nothing to do with reserved words. It's just a list that equates to ints. The code in this zip file is right out of Ron Maks C++ compiler design book. He was a teaching professor at some prestigious university (now probably retired), wrote several books (2 on compilers). Do you really believe that the code from his book was never any good? Have compilers changed this much over time?
    maxcy/wt1v

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Really?

    And what is a compiler supposed to do with an expression like this containing your 'enum' values.
    if ( and and or )

    > Have compilers changed this much over time?
    It seems far more likely that someone is taking really old C code (where those words would indeed be valid enum members) and shoe-horning it into C++ without knowing what they're doing.

    'and', 'or' have always been part of C++, so that enum was never valid C++ in any version of the language.
    C++ keywords - cppreference.com

    Compare with the list of C keywords
    C keywords - cppreference.com
    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
    Join Date
    Aug 2023
    Posts
    45

    Thumbs up

    I've been focusing on this project too long. All the enums are passed as function parameters so the compiler could see the difference between a reserved word and an enum, but your example blows that out of the water!!! I did get the last chapter of this book fixed up and running. Now it compiles a simple Pascal program into assembly code. I would now consider this thread no longer needed, so I would mark it as completed as I do in other forums. But, alas, I can find no way to do so in this forum!
    Thanks for all the help!!! maxcy/wt1v

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with enum
    By purestr999 in forum C Programming
    Replies: 8
    Last Post: 11-24-2010, 03:57 AM
  2. Enum List problem
    By scott_ill in forum C# Programming
    Replies: 2
    Last Post: 07-09-2009, 06:26 AM
  3. Enum problem
    By deviousdexter in forum C# Programming
    Replies: 5
    Last Post: 05-06-2009, 07:46 AM
  4. Problem with enum and files
    By Robert_Sitter in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2005, 01:40 AM
  5. enum code problem
    By correlcj in forum C++ Programming
    Replies: 4
    Last Post: 11-15-2002, 11:00 PM

Tags for this Thread