Absolutely! See below :)

On Thu, 2007-01-18 at 15:32 -0500, Peter Jay Salzman wrote:
> 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); \
>       }
> 

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

> 
> 
> int main( void )
> {
>       char *p = NULL;
>       CHECK_FOR_NULLITITY( p, "p" );
> 
>       return 0;
> }
> _______________________________________________
> vox-tech mailing list
> [email protected]
> http://lists.lugod.org/mailman/listinfo/vox-tech
-- 
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/

_______________________________________________
vox-tech mailing list
[email protected]
http://lists.lugod.org/mailman/listinfo/vox-tech

Reply via email to