|
Re: Why it works with an underscore?
#defines are very simple.
At their simplest (you can do a lot of wierd stuff with them, but that's for another day), you have:
#define <text to replace> <text to replace with>
So if you did
#define *Sensor_variable read*
Then anytime you typed "*Sensor_variable", it would replace it with "read*". Unless you didn't mean the asterisks to be there, then it would do the same thing without the asterisks.
This means you can do things like
#define test pwm01;
The preprocessor (thing that processes everything that starts with #) doesn't care WHAT you put after the first argument to a define, it will go to the end of the line and replace all instances of "test" with "pwm01;". Note that the semicolon is in there. That means that if you wrote
test = 5;
Then after the preprocessor was done, it'd look like
pwm01; = 5; // compile error woo-hoo
because it replaced "test" with "pwm01;". So be careful of what you put as the second argument to #define, or else it might not make sense.
For a good example of #defines, take a look at the given code in ifi_aliases.h. The entire file is IFI just re-defining big ugly expressions as easy-to-use things like pwm01, pwm02, rc_dig_in01, etc. You just need to do the same thing.
Last edited by Bongle : 05-01-2007 at 20:23.
|