about #define params

Started by
7 comments, last by IFooBar 21 years, 8 months ago
hello i have this log function and its really long to write all the time...goes like this g_log->insert(LOG_INFO, "blah %d", var); i want to make a define for it so that it becomes easy like LOG_INFO("blah", var); but when i do #define LOG_INFO(x,...) g_log->(LOG_INFO, x,...); it gives me an error with the 3 dots thingy. is there anyway i can use the 3 dots in a define? thanks

Al **MY HQ**
[size=2]aliak.net
Advertisement
the compiler simply substitutes what is in the #define, for whever is defined.

For instance

#define APP CApp::Get()

int main()
{
APP->Stuff();
}

would become

int main()
{
CApp::Get()->Stuff();
}

You can take this principle and appy it to your own stuff.

try

#define LOG g_Log->Insert

then whenever you do LOG(stuff, more stuff, ...) it expands to g_log->Insert(stuff, more stuff, ...)

Those who dance are considered insane by those who cannot hear the music.
If I recall correctly:

#define BLAH(a, b, c, ...) something_else(a, b, c, __VA_ARGS__)
#define BLAH(a, b, c, ...) something_else(a, b, c, __VA_ARGS__)
dosnt work but
#define BLAH(a, b, c, __VA_ARGS__) something_else(a, b, c, __VA_ARGS__)

seems to be working thanks!!




Al
**MY HQ**
[size=2]aliak.net
in fact even
#define BLAH(a, b, c, ANYTHING) something_else(a, b, c, ANYTHING)

seems to be working. so i guess u can just replace the ''...'' with any var and in place.




Al
**MY HQ**
[size=2]aliak.net
quote:Original post by alfmga
in fact even
#define BLAH(a, b, c, ANYTHING) something_else(a, b, c, ANYTHING)

seems to be working. so i guess u can just replace the ''...'' with any var and in place.


However, will you be able to pass more than 4 args to BLAH? That is part of the functionality you want is it not?
The C99 standard supports this behaviour, although the C++ standard and ANSI C standard do not. So, it''s really compiler dependant, I know that some compilers have extensions to support this (MSVC does not). The GCC compiler supports this as part of C99.
quote:
will you be able to pass more than 4 args to BLAH?


crap! no.

quote:
That is part of the functionality you want is it not?


yeah.

quote:
I know that some compilers have extensions to support this (MSVC does not).


crap again!

thanks anyway people




Al
**MY HQ**
[size=2]aliak.net
Why not create a global function that gets inlined? ^_^

This topic is closed to new replies.

Advertisement