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

Walter Bright bright at dataioDataio.UUCP
Sat Feb 1 04:00:53 AEST 1986


In article <887 at h-sc1.UUCP> augart at h-sc1.UUCP (Steven Augart) writes:
>Could someone on a non-4.2/4.3 BSD machine tell us if this facility is
>part of other preprocessors as well?  Thanks.

__LINE__ and __FILE__ are supported by the Datalight C compiler for the
IBM PC. In fact, they are supported by most C compilers. They are
primarilly useful to support the following macro:

#define assert(e)	((e) || assert_fail("e",__LINE__,__FILE__))

assert_fail(expression,line,file)
char *expression,*file;
int line;
{
	fprintf(stderr,"expression '%s' failed at line %d in file '%s'\n",
		expression,line,file);
	exit(1);
}

The assert macro generates code that guarantees that expression e evaluates
to true, or else tells you where it failed. Sprinkling your code with
assert()s in the right places can greatly facilitate debugging (especially
on the IBM PC which has no memory protection).
Note the "e" in the macro definition. This won't work on all compilers,
you will have to use a variant that your compiler supports.



More information about the Comp.lang.c mailing list