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**
about #define params
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, ...)
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, ...)
#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**
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**
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**
#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**
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**
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement