CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Alternative to #define to literally replace a string?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Alternative to #define to literally replace a string?
PostPosted: Wed Apr 19, 2006 1:30 pm     Reply with quote

My problem is that I'm tring to redefine a function such as:

#define output_high(LED) output_high_portb0()

If this was taken literally how it was written, it would only replace this particular string, resulting in my function being called for the LED pin, and the CCS functions for all other pins. Which is what I want.
However CCS recognises it as some sort of macro and tries to match up the parameters in the brackets. It compiles without error but no code seems to be generated for all instances of output_high() apart from instances of output_high(LED), of which my custom code appears.

Is there any way I can get round this so the #define is taken literally as it is written?
Ttelmah
Guest







PostPosted: Wed Apr 19, 2006 2:28 pm     Reply with quote

Not really.
#define, _is_ a macro language. This is not a problem with CCS, but standard C.
Items in brackets after the identifier, are taken as parameters to the declaration.
You can do something like:
Code:

#define LED (1)

#define output_h(x) if(x==LED) output_high_portb0();\
else output_high(x)


However you cannot have this defined as 'output_high', since you will then get a recursive declaration.

Best Wishes
Guest








PostPosted: Wed Apr 19, 2006 5:29 pm     Reply with quote

Thought I would be out of luck!

OK thanks for your help Ttelmah.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group