How about a predefined #FILE, #PATH

aglew at ccvaxa.UUCP aglew at ccvaxa.UUCP
Wed Jan 29 13:31:00 AEST 1986




Aztec C on the IBM PC has the "predefined variable names"
__FILE__, __LINE__, __FUNC__, which are actually compile time
"constants" at any place in the code (macros work fine).

Combining these with the new standard for concatenation of string constants
made it easy to produce some half-decent error messages:

puts("Error in " __FUNC__ " at line " __LINE__ " of file " __FILE__);

Unfortunately, although this was described in the manual, it didn't work
in the version of the compiler we had.
I don't have a manual for the ANSI C standard, so I don't know if these
are included.

PS. If you really want to use #defines, something like this csh alias 
might be useful:

	alias CC	cc -DFILE=\!:1 \!:1.c -o \!:1

and a little lexer can do the required substitutions for line number and
function.



More information about the Comp.lang.c mailing list