Board index » cppbuilder » defines

defines


2008-02-02 12:01:30 AM
cppbuilder69
I have a single program that I want to be able to change some of it's
internal workings at compile time.
For Instance, I have three different analog cards.
Is this the proper way to do it?
#define card100
// #define card101
// #define card102
then in my source....
#ifdef card100
{
...
}
else
#ifdef card101
{
....
}
else
#ifdef card102
{
.....
}
 
 

Re:defines

"Richard" < XXXX@XXXXX.COM >writes:
Quote
I have a single program that I want to be able to change some of it's
internal workings at compile time.
For Instance, I have three different analog cards.

Is this the proper way to do it?
No. The curly braces are superfluous. And the preprocessor won't
interpret the "else" lines.
[And I prefer if defined() to ifdef, but that's a matter of taste.]
Quote
#define card100
// #define card101
// #define card102

then in my source....
#ifdef card100
{
...
}
else
#ifdef card101
{
....
}
else
#ifdef card102
{
.....
}
#if defined(card100)
...
#elif defined(card101)
...
#elif defined(card102)
...
#endif
But if the ... is more than very simple code, consider creating three
card specific source files and including only the desired one in the
project.
 

Re:defines

Thanks Thomas.
"Thomas Maeder [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
"Richard" < XXXX@XXXXX.COM >writes:
#if defined(card100)
...
#elif defined(card101)
...
#elif defined(card102)
...
#endif

But if the ... is more than very simple code, consider creating three
card specific source files and including only the desired one in the
project.
 

{smallsort}