| Author |
Message |
UncleanSpirit
Joined: 04 Nov 2003 Posts: 9
|
10 May 2006 3:03 Re: Beginning C user having trouble using #define with funct |
|
|
|
|
I'm trying to use a #define pre-processor directive to pass a parameter to a function but the compiler is throwing an error that it expects a numeric argument passed to the function, like a number or C variable that can be evaluated. Here is a portion of my code relevant to the problem issue.
| Code: |
#define OFF = 0
#define ON = 1
void power_relays( int on_off)
{
// do stuff here
}
void main( void )
{
while ( TRUE )
{
power_relays( OFF );
delay_ms ( 500);
power_relays( ON );
delay_ms ( 500);
}
}
|
If someone would correct me, I would appreciate it.
Added after 37 minutes:
Never mind. I found my stupid mistake of using "=" with a preprocessor #define.
|
|
| Back to top |
|
 |
Google AdSense

|
10 May 2006 3:03 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
semiconductor
Joined: 04 Apr 2003 Posts: 294 Helped: 3 Location: France
|
10 May 2006 3:19 Re: Beginning C user having trouble using #define with funct |
|
|
|
|
It would be better
| Code: |
#define OFF 0 //without "="
#define ON 1 //without "="
void power_relays( int on_off)
{
// do stuff here
}
void main( void )
{
while ( TRUE )
{
power_relays( OFF );
delay_ms ( 500);
power_relays( ON );
delay_ms ( 500);
}
} |
|
|
| Back to top |
|
 |
nikhil_damle
Joined: 15 Dec 2005 Posts: 103 Helped: 2
|
10 May 2006 11:03 Re: Beginning C user having trouble using #define with funct |
|
|
|
|
| It will be more appropriate if u use the OFF/On replaces by True/False
|
|
| Back to top |
|
 |