-
Debugging question
if I have the following function
Code:
inline void SHOWERROR(char *str)
{
#ifdef _DEBUG
char buf[1024];
char file[] = __FILE__;
int line = __LINE__;
sprintf(buf, "File: %s\nLine: %d\n%s", file, line, str);
MessageBox(0, buf, "Error", 0);
#endif
}
Assuming _DEBUG was not defined, would the compiler generate any extra instruction in this if statement?
Code:
if (!(memcpy(pDest, pSource, size) ) )
{
SHOWERROR("Error Message");
}
or would it be better to use something like this
Code:
#define SHOWERROR(s) { char buf[1024]; \
char file[] = __FILE__; \
int line = __LINE__; \
sprintf(buf, "File: %s\nLine: %d\n%s",file,line,s); \
MessageBox(0, buf, "Error", 0); }
...
if (!(memcpy(pDest, pSource, size) ) )
{
#ifdef _DEBUG
SHOWERROR("Error Message");
#endif
}
-
An empty inline function should be completely eliminated by the compiler.
Your first approach seems fine to me.
-
I'm not sure if the compiler eliminates it or not, but I usually write debug functions like this:
Code:
#ifdef _DEBUG
void DBG_FUNC( int param )
{
...
}
#else
# define DBG_FUNC( param )
#endif