• Support PF! Buy your school textbooks, materials and every day products Here!

Issue Using Defines In C

  • Thread starter Lancelot59
  • Start date
  • #1
634
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:
//*****************************************************************************
//Motor Control Functions
//*****************************************************************************
void forward(void)			//Go striaght forward
{
	motorR(THROTTLE,TRIM);
	motorL(THROTTLE,TRIM);
}
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:
#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.
 

Answers and Replies

  • #2
125
0
Show error messages.
 
  • #3
D H
Staff Emeritus
Science Advisor
Insights Author
15,393
683
Get rid of the equals sign.

#define THROTTLE fast
 
  • #4
634
1
Get rid of the equals sign.

#define THROTTLE fast
...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.
 
  • #5
33,481
5,171
The code your compiler saw was this.
Code:
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.
 
  • #6
634
1
I see, that makes sense.
 

Related Threads on Issue Using Defines In C

  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
3
Views
5K
  • Last Post
Replies
6
Views
1K
  • Last Post
Replies
4
Views
2K
Replies
3
Views
2K
Replies
9
Views
12K
  • Last Post
Replies
2
Views
1K
Replies
0
Views
1K
  • Last Post
Replies
7
Views
7K
Top