03-03-2011 01:38 PM
I finally isolated my problem to the use of __FUNCTION__ (a predefined macro) in the following code:
#define debug_printf(debug,lvl,x) do { \
if ( ! __debug_printf_check( debug, lvl ) ){ \
__debug_lock(); \
__debug_printf ( "%s:%s:%d: ",__FILE__, __FUNCTION__, __LINE__); \
__debug_printf x ; \
__debug_unlock();\
}\
} while(0)
where __debug_printf is defined as follows:
void __debug_printf(const char * format, ... )
{
//int diagnostic = 1;
va_list ap;
//if (diagnostic)
//return;
if (output_enabled & CONSOLE_OUTPUT){
va_start (ap, format);
vfprintf ( stderr, format, ap );
va_end(ap);
}
if (output_enabled & UI_OUTPUT){
va_start (ap, format);
ui_debug_printf( format, &ap);
va_end(ap);
}
if ( output_enabled & FILE_OUTPUT){
va_start (ap, format );
if (fp != NULL) vfprintf ( fp, format, ap );
va_end (ap);
}
}
The program wouldn't crash on every invocation of __debug__printf, but it would consistently crash at the same point in our code. __FUNCTION__ is actually redundant, since FILE and LINE are given, so I removed any reference to __FUNCTION__ and the crash problem disappeared. It was a pain to find this bug.
03-03-2011 01:55 PM
Are you using C99?
C99 added the __func__ mechanism, I think the __FUNCTION__ macro is something NI did.
Even if you're using C99, it's not certain that NI would have implemented __func__. __func__ is actualy a block scope local (stack) variable, not a macro, so you may get better behavior with it if it's available.
But like you say you know the file and line so it's not really needed.