|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Alternative to #define to literally replace a string? |
Posted: Wed Apr 19, 2006 1:30 pm |
|
|
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
|
|
Posted: Wed Apr 19, 2006 2:28 pm |
|
|
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
|
|
Posted: Wed Apr 19, 2006 5:29 pm |
|
|
Thought I would be out of luck!
OK thanks for your help Ttelmah. |
|
|
|
|
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
|