How about a predefined #FILE, #PATH and #FUNCTION for C?

Steven Augart augart at h-sc1.UUCP
Tue Jan 28 08:43:02 AEST 1986


I cannot claim to speak about other versions of unix, but in Berkeley
4.2 and 4.3, there are two macros automatically defined for you by the
c preprocessor: __FILE__ and __LINE__.

Here's how I use them:
char * foo;
char * malloc();
unsigned room;
[ code .... ]
if ((foo = malloc(room)) == (char *) NULL)
{
    fprintf(stderr, "Out of memory on line %d of file %s!\n", __LINE__, 
			__FILE__);
    exit(1);
}

Could someone on a non-4.2/4.3 BSD machine tell us if this facility is
part of other preprocessors as well?  Thanks.

Steven Augart
swa at borax.lcs.mit.edu
(617) 498-6352



More information about the Comp.lang.c mailing list