0

How do I change this code from c++ to c if I can't use "::" to denote enum variables/elements? Also, I keep getting an "identifier 'GameState' is unidentifed" error message any time it's used outside the enum declaration that seems to be related to this problem somehow?

Header

void gameStateManager(); 
typedef enum GameState
    {
        MENU, PLAY, EXIT
    };

GameState gameState;

Source

void gameStateManager()
    {
        switch (gameState)
        {
            case GameState::MENU:
            //button press selections that lead to Menu
            break;

            case GameState::PLAY:
            //button press selections that lead to Play
            break;

            case GameState::EXIT:
            //button press selections that lead to Exit 
            SDL_QUIT;
            break;
Jeffrey
  • 37
  • 6
  • 4
    You have asked and got an answer to an almost identical question here: https://stackoverflow.com/questions/68038720/enum-issue-when-converting-from-c-to-c – Eugene Sh. Jun 18 '21 at 18:11
  • You appear to be porting from C++ to C without knowing C. Is that the case? If so, you ought to learn C first from a [good C book](https://stackoverflow.com/a/562377/4641116) ... alas, note the disclaimer about the list also containing some less-than-good books. – Eljay Jun 18 '21 at 18:29
  • Yes, I tried asked addressing these issues together, but was told to split them apart. Changing "GameState::MENU" to "GameState == MENU" or "gameState == MENU" doesn't work. Error: expression must have constant value. The while loop fix in the question you referenced does not solve the switch/case issue. – Jeffrey Jun 18 '21 at 18:29
  • Just change to `EXIT` or `MENU` (so long as the definition of the `enum` is visible to that code). – Adrian Mole Jun 18 '21 at 18:31
  • Yes and no regarding not learning C. Most of the basic programming I learned for C++ seems to translate just fine to C and the libraries I want to use are all backwards compatible. None of my programs are really very complex. But once I debug this code, I will be looking for some good primary literature. – Jeffrey Jun 18 '21 at 18:38
  • Then why port to C? – Ben Jun 19 '21 at 02:43

0 Answers0