R
Ralph A. Moeritz
Hello,
I have a macro called XMALLOC. It feels hacked and dirty
and I'm not even sure if its valid C (gcc accepts it, and
it _seems_ to work - but that could be co-incident). Any
suggestions on how to improve it?
Thanks,
Ralph
void *xMaLlOcTmP001_ = NULL;
#define XMALLOC( size ) \
( xMaLlOcTmP001_ = malloc( size ) ) \
? xMaLlOcTmP001_ \
: ( fprintf( stderr, "malloc() failed near %s:%d\n", \
__FILE__, __LINE__ ), \
exit( EXIT_FAILURE ), NULL )
I have a macro called XMALLOC. It feels hacked and dirty
and I'm not even sure if its valid C (gcc accepts it, and
it _seems_ to work - but that could be co-incident). Any
suggestions on how to improve it?
Thanks,
Ralph
void *xMaLlOcTmP001_ = NULL;
#define XMALLOC( size ) \
( xMaLlOcTmP001_ = malloc( size ) ) \
? xMaLlOcTmP001_ \
: ( fprintf( stderr, "malloc() failed near %s:%d\n", \
__FILE__, __LINE__ ), \
exit( EXIT_FAILURE ), NULL )