Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4126196
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:58:09+00:00 2026-05-20T23:58:09+00:00

I have a file that has many #define statements such as – #ifndef UTILITY_H

  • 0

I have a file that has many #define statements such as –

#ifndef UTILITY_H
#define UTILITY_H
#define BUMP 7;
#define WHEEL_DROPS 7;
#define WALL 8;
#define CLIFF_LEFT 9;
#define CLIFF_FRONT_LEFT 10;
#define CLIFF_FRONT_RIGHT 11;
#define CLIFF_RIGHT 12;
#define VIRTUAL_WALL 13;
...
... 
#endif

The list goes on to about 42 different values. I include this file into my other files, but whenever I try to use one of these constants I get errors. For a specific example, I try to do –

Sensor_Packet temp;
temp = robot.getSensorValue(BUMP); //line 54
cout<<temp.values[0]<<endl;

The errors I get are –

main.cpp:54: error: expected ‘)’ before ‘;’ token
main.cpp:54: error: expected primary-expression before ‘)’ token
main.cpp:54: error: expected ‘;’ before ‘)’ token

I don’t see why I am getting these errors because BUMP is already defined. This also happens when I try to use a switch statement with the cases being the defines –

switch(which) {
case BUMP:
    //do stuff
case CLIFF_LEFT:
   //do stuff
}

Is there something I am leaving out about using #define? I thought all I had to do was define a constant and then I could just call it. Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:58:09+00:00Added an answer on May 20, 2026 at 11:58 pm

    Take a closer look at your #defines:

    #define BUMP 7;
    

    This tells the preprocessor to replace BUMP with 7;. Note that the macro definition includes the semicolon!

    So your code actually looks like this to the compiler:

    Sensor_Packet temp;
    temp = robot.getSensorValue(7;);
    cout<<temp.values[0]<<endl;
    
    // ...
    
    switch(which)
    {
    case 7;:
        // do stuff
    case 9;:
        //do stuff
    }
    

    Which are clearly syntax errors. To fix this, remove the semicolons in your #define statements.

    But in C++, you should be using const ints or enums for constants instead of #defines. Here are some possible examples:

    enum CliffPositions
    {
        CLIFF_LEFT  = 9,
        CLIFF_FRONT_LEFT = 10,
        CLIFF_FRONT_RIGHT = 11,
        CLIFF_RIGHT = 12,
    };
    
    enum WallType
    {
        WALL = 8,
        VIRTUAL_WALL = 13;
    }
    
    const int BUMP = 7;
    const int WHEEL_DROPS = 7;
    
    // etc ...
    

    This way is preferable because unlike #defines, const ints and enums respect scope and are more type-safe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a file that has a 64 bit integer as a string in
I have a file that has one entry per line. Each line has the
I have a HTML file that has code similar to the following. <table> <tr>
I have a jar file that has a file named client.ts in (when viewing
I have an Excel file that has a bunch of VBA and macro code
Scenario: I have a text file that has pipe (as in the | character)
I have a flat-file schema that has a header and detail records. It looks
I have a file in cvs that has Sticky Options set to -kk .
I have a simple WPF (XAML) file that has some animated shapes and text.
I have a rather large text file that has a bunch of missing newlines,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.