1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Issue Using Defines In C

  1. Mar 18, 2010 #1
    This is once again for my robot. My current issue is with a define command:

    I have the following function defined in motor_control.c:

    Code (Text):

    //Motor Control Functions
    void forward(void)          //Go striaght forward
    The throttle value controls speed, trim offsets the speed variable. Although it probably will be eliminated.

    Anyhow, I have throttle defined in a header called system_config.h:

    Code (Text):

    #define THROTTLE = fast     //Default forward throttle value to use
    The value for "fast" has been enumerated in the header for motor_control.c

    I have included the system_config.h file in the motor_control.c library, so what can't I see it? As far as I'm aware it should be able to see that defined value.
  2. jcsd
  3. Mar 18, 2010 #2
    Show error messages.
  4. Mar 18, 2010 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Get rid of the equals sign.

    #define THROTTLE fast
  5. Mar 18, 2010 #4
    ...That was a silly mistake. Thanks for the catch.

    The only error message I got was a syntax error when the compiler got to the first function that tried to pass THROTTLE to a function. It didn't say anything else.

    Thanks again for the help.
  6. Mar 18, 2010 #5


    Staff: Mentor

    The code your compiler saw was this.
    Code (Text):

    motorR(= fast,TRIM);
    motorL(= fast,TRIM);
    The reason for this is that the #define preprocessor directive does nothing more than text replacement. This is why you DON'T want to put = in simple preprocessor directives.
  7. Mar 18, 2010 #6
    I see, that makes sense.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Issue Using Defines Date
Find the current using Nodal Analysis Sunday at 6:49 AM
Stiffness matrix issue Feb 14, 2018
Thevenin's theorem issue Oct 7, 2017
Mole balance issue with volume division Apr 19, 2017
KCL equation issue Oct 30, 2016