[vox-tech] C preprocessor - "soft reference"?

Peter Jay Salzman p at dirac.org
Thu Jan 18 12:32:18 PST 2007


The variable p and the variable's name "p" need to be passed to the macro
function to test for nullness and then to print some message involving the
variable's name.

Is there a crafty way of doing this so that only one thing needs to be
passed?

Thanks!





#include <stdlib.h>
#include <stdio.h>

#define CHECK_FOR_NULLITITY(var,varname) \
	if ( (var) == NULL ) \
	{ \
		printf("%s is null.\n", varname); \
		exit(EXIT_FAILURE); \
	}



int main( void )
{
	char *p = NULL;
	CHECK_FOR_NULLITITY( p, "p" );

	return 0;
}


More information about the vox-tech mailing list