How about a predefined #FILE, #PATH and #FUNCTION for C?
Joseph Grace
grace at yale.ARPA
Mon Jan 27 12:42:13 AEST 1986
To explain what I mean...
definition by example:
#PATH ==> /usr/fred/hello.c
#FILE ==> hello.c
#FUNCTION ==> main
(N.B.: no quotation marks.)
2 problems that these predefined macros would help (me) with:
1)
When debugging, I always like to include in my error messages, the
name of the file where the error message originated. However, when
I rename files with more meaningful names, or simply copy a function
from one file to another, the old filename still shows up in the
error (or other) messages. #FILE would put a stop to this.
2)
#FILE could also help in writing a header file, e.g., error.h, that
has standard error messages that will print the filename of the file
that the message printed from.
Here is an example where these predefined macros would be useful:
(#FILE ==> FILE since compiler complains "illegal macro name" with
#FILE.)
error.h:
#define TEST printf ("FILE: error has occurred\n");
test.c:
#define FILE test1
#include "test.h"
main()
{
TEST;
}
output of test (on BSD 4.2 Pyramid):
FILE: error has occurred
/* not "test: error has occurred" as I would prefer */
#FILE, #PATH and #FUNCTION would solve these problems.
If someone knows a way around these problems, I would appreciate hearing
about it.
Otherwise, maybe these would be good additions to the C standard...
Sincerely,
Joseph R. Grace
...decvax!yale!grace
p.s. #PATH is nice for files that reside in many directories.
#FUNCTION is nice for precision.
More information about the Comp.lang.c
mailing list