electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

Beginning C user having trouble using #define with functions


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Beginning C user having trouble using #define with functions
Author Message
UncleanSpirit



Joined: 04 Nov 2003
Posts: 9


Post10 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
Google Adsense




Post10 May 2006 3:03   

Ads




Back to top
semiconductor



Joined: 04 Apr 2003
Posts: 294
Helped: 3
Location: France


Post10 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


Post10 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
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> Beginning C user having trouble using #define with functions
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Having trouble with PORTB and A (need help) (2)
hfss questions from beginning user (2)
Having trouble doing this differential equation ... (2)
having trouble for 435 Mhz Yagi antenna Input impedance (5)
trouble with 4-bit lcd using LP2114 (3)
Define and plot functions in Cadence (5)
3GPP LTE code - having trouble about the simulation code (3)
user defined functions in VHDL (3)
defining user waveforms and functions in Cadence (3)
Beginning with Microcontrollers and Zigbee (1)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS