Thread: #old c code #convert

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

    Post #old c code #convert

    I have a compiler error about converting an int to enum. (scanner3) scanner1 shows where the error occurs trying to convert an int to a TOKEN_CODE(yellow) at the end of the initialization list. I think the NULL, 0 at the end of the enum list was a kind of end marker. scanner2 shows the enum typedef for the TOKEN_CODE enum. I guess this could be done with older c compilers. I kind of remember that one could use int indexes into an enum, but I'm not sure about this idea. How do I get around this mess?
    maxcy
    Attached Images Attached Images #old c code #convert-scanner1-png #old c code #convert-scanner2-png #old c code #convert-scanner3-png 

  2. #2
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    277
    Quote Originally Posted by maxcy View Post
    I have a compiler error about converting an int to enum. (scanner3) scanner1 shows where the error occurs trying to convert an int to a TOKEN_CODE(yellow) at the end of the initialization list. I think the NULL, 0 at the end of the enum list was a kind of end marker. scanner2 shows the enum typedef for the TOKEN_CODE enum. I guess this could be done with older c compilers. I kind of remember that one could use int indexes into an enum, but I'm not sure about this idea. How do I get around this mess?
    maxcy
    Why not just use 'NO_TOKEN' in place of the literal '0'? Otherwise, you could redefine 'token_code' to be a plain 'int'. As the compiler message say, you can also use the -fpermissive flag to cause a warning to be a raised instead of an error.

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

    No_token

    I did try this suggestion and it worked. Since NO_TOKEN was at the beginning on the enum list, it should evaluate to 0 which is what I needed.
    txs maxcy

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. help convert code to C++...
    By lavenzo in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2011, 07:30 AM
  3. Comment each line and convert this C++ OOP code into C++ code.
    By Shayaan_Mustafa in forum C++ Programming
    Replies: 3
    Last Post: 01-03-2011, 01:23 PM
  4. convert vb.net code to C#
    By Nyoud33 in forum C# Programming
    Replies: 3
    Last Post: 01-11-2009, 03:29 PM
  5. Replies: 14
    Last Post: 04-01-2008, 02:23 AM

Tags for this Thread