log file
-
Hi, I wrote a function with variable parameters to do some log stuff in my project. The function prototype looks like this :
static void write(char* str,...);
What I wish to do is to link this function to a #define so that I can easily get rid of all my logs. The code should look like this :#ifdef _DEBUG #define VCNLOG(x) write(x) #else #define VCNLOG(x) #endif // somewhere else... VCNLOG("my value is %i",var);
But this doesn't work due to the variable parameters (Visual complains about too much parameters in macro VCNLOG) Any idea of how to get this work ? thanks, Ed -
Hi, I wrote a function with variable parameters to do some log stuff in my project. The function prototype looks like this :
static void write(char* str,...);
What I wish to do is to link this function to a #define so that I can easily get rid of all my logs. The code should look like this :#ifdef _DEBUG #define VCNLOG(x) write(x) #else #define VCNLOG(x) #endif // somewhere else... VCNLOG("my value is %i",var);
But this doesn't work due to the variable parameters (Visual complains about too much parameters in macro VCNLOG) Any idea of how to get this work ? thanks, Ed#ifdef _DEBUG #define TEST test #else //#define TEST #define TEST 0 #endif void test(int, ...) { std::cout << "Hello, World from test() \n"; } int _tmain(int argc, _TCHAR* argv[]) { TEST(5, std::cout << "Hellow, World from _tmain! \n"); return 0; } Note that if #define TEST in Release mode, the test() function will never get called, but its parameters are get evaluated; so if you do not want this side effect, use: #define TEST 0 Regards, Serge
-
Hi, I wrote a function with variable parameters to do some log stuff in my project. The function prototype looks like this :
static void write(char* str,...);
What I wish to do is to link this function to a #define so that I can easily get rid of all my logs. The code should look like this :#ifdef _DEBUG #define VCNLOG(x) write(x) #else #define VCNLOG(x) #endif // somewhere else... VCNLOG("my value is %i",var);
But this doesn't work due to the variable parameters (Visual complains about too much parameters in macro VCNLOG) Any idea of how to get this work ? thanks, EdOne solution:
static void write(char* str,...)
{
#ifdef _DEBUG
write to log file here
#endif
}Now all of the calls to
write()
can remain untouched.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
One solution:
static void write(char* str,...)
{
#ifdef _DEBUG
write to log file here
#endif
}Now all of the calls to
write()
can remain untouched.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
The following was based on how it is done in MFC (Afx.h):
// MyTrace.h
#ifndef __MYTRACE_H__
#define __MYTRACE_H__void MyTrace(int nLevel, LPCTSTR pFmt, ...);
#ifdef _DEBUG
#define MYTRACE MyTrace
#else
#define MYTRACE 1 ? ((void)0) : MyTrace
#endif#endif // __MYTRACE_H__
INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen
-
The following was based on how it is done in MFC (Afx.h):
// MyTrace.h
#ifndef __MYTRACE_H__
#define __MYTRACE_H__void MyTrace(int nLevel, LPCTSTR pFmt, ...);
#ifdef _DEBUG
#define MYTRACE MyTrace
#else
#define MYTRACE 1 ? ((void)0) : MyTrace
#endif#endif // __MYTRACE_H__
INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen
Yes, that is another way.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
Yes, that is another way.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
ok, I'll try that. In fact the idea is not to include the parameters in the define... What I don't understand is what it will do in release mode : 0(myparameters). This should crash, shouldn't it ? Or maybe there's something I missed in #define principle ;) thanks Ed
-
ok, I'll try that. In fact the idea is not to include the parameters in the define... What I don't understand is what it will do in release mode : 0(myparameters). This should crash, shouldn't it ? Or maybe there's something I missed in #define principle ;) thanks Ed
Ed01 wrote: What I don't understand is what it will do in release mode : 0(myparameters). This should crash, shouldn't it ? Or maybe there's something I missed in #define principle The function gets called the same in release mode as it is in debug mode. The only difference is that the body of the function is "missing" in debug mode.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow