> If printf does not print "(null)" but causes a core
> dump, it is not possible
> to add _simple_ debug statements to your code in many
> cases...
#ifdef DEBUG
const char *_safestr(const char *s)
{
return ((s!=NULL)?s:"(null)");
}
#define SAFESTR(s) _safestr(s)
#else
#define SAFESTR(s) s
#endif
...
printf("this is my string: %s\n",SAFESTR(s));
What's so hard about something like that, which allows choosing
which behavior to use at compile-time with zero penalty in the non-debug
case, while still being explicit about what one is doing? (note: I did it as a
function and macro rather than just a macro to avoid problems with macro
arguments that have side-effects)
BTW, I didn't check if the function and macro names don't conflict with
anything, so don't just use that verbatim. Also, one would probably want
to put _safestr() (or whatever one called it) in a lib, and just have the
conditional code declare but not define it.
This message posted from opensolaris.org
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code