Not really, because macros are not part of the actual language, but are instead replaced before the compiler actually starts parsing the program logic.
That is... the compiler doesn't even see this:
It sees this:
|
func("ifconfig eth0 up");
|
I won't get into the
many many many reasons why you probably should not be using macros. But you can have a similar effect simply giving these a type:
1 2 3 4 5 6 7 8 9 10
|
const char* UP = "whatever";
const char* DOWN = "something else";
void func(const char* temp)
{
if( temp == UP )
something();
else
somethingelse();
}
|
However this also is problematic because:
1) It assumes all macros you pass to the function are
const char*
s.
2) If you have two macros that are identical you get undefined behavior (the compiler might differentiate them, or it might not -- depending on how optimized they are).
The safer way would be to just strcmp() the passed string:
1 2 3 4 5
|
void func(const char* temp)
{
if( !strcmp(temp, UP) )
something();
}
|
Or use the actual string class:
1 2 3 4 5
|
void func(const string& temp)
{
if( temp == UP )
something();
}
|
Both of these will work, but will not differentiate between two constants that are defined the same way.