M
Michael B Allen
How does the following work and is it portable?
/*
this uses a little trick to allow __LINE__ to be stringified
*/
#define _STRING_LINE_(s) #s
#define _STRING_LINE2_(s) _STRING_LINE_(s)
#define __LINESTR__ _STRING_LINE2_(__LINE__)
#define __location__ __FILE__ ":" __LINESTR__
Result:
printf("%s", __location__);
becomes:
printf("%s", "t0.c" ":" "27");
and prints:
t0.c:27
Mike
PS: macros found in talloc.h at junkcode.samba.org
/*
this uses a little trick to allow __LINE__ to be stringified
*/
#define _STRING_LINE_(s) #s
#define _STRING_LINE2_(s) _STRING_LINE_(s)
#define __LINESTR__ _STRING_LINE2_(__LINE__)
#define __location__ __FILE__ ":" __LINESTR__
Result:
printf("%s", __location__);
becomes:
printf("%s", "t0.c" ":" "27");
and prints:
t0.c:27
Mike
PS: macros found in talloc.h at junkcode.samba.org