J
Jacek Dziedzic
Hello!
I am working on a code which features the following macros:
#define myname \
((std::string)(abi::__cxa_demangle(typeid(myself).name(),\
0,0,&(Framework::demangle_status))))
#define $$ \
((std::string) "class: " + myname + "\nfunction: " + \
(std::string) __PRETTY_FUNCTION__ ),
These are then used within throw statements like this:
if(!out) logged throw EIOWriteError($$ filename);
The purpose of all this is to facilitate passing the
name of the offending class method to the catch() clause
later on, without having to type it manually within the
throw part. ("logged" evaluates to whitespace if exception
logging is off and to some log-writing magic if exception
logging is on).
Anyway, the '$' character was chosen for the job as
it is unlikely to collide with anything in the source
code (I know, macros are evil). Everything worked fine
until I tried the "-ansi" compiler switch. I was surprised
to see that the compiler complains about the '$' character.
The intel compiler produced an error "expected an identifier"
on the #define line. g++ does not complain in "-ansi" mode,
only after adding "-pedantic" it produces a warning
"$ in identifier or number" on the #define line.
This is surprising me -- shouldn't the preprocessor
have already replaced all occurrences of "$$" with the
macro they represent?
Which compiler behaves in a Standard-compliant manner?
Anyway, can someone tell me what exactly the Standard
says on what characters are allowed in the source code,
both at the before-preprocessor and after-preprocessor
level? I thought you could have anything in your source
files, provided that the preprocessor then replaces
it with something reasonable...
TIA,
- J.
I am working on a code which features the following macros:
#define myname \
((std::string)(abi::__cxa_demangle(typeid(myself).name(),\
0,0,&(Framework::demangle_status))))
#define $$ \
((std::string) "class: " + myname + "\nfunction: " + \
(std::string) __PRETTY_FUNCTION__ ),
These are then used within throw statements like this:
if(!out) logged throw EIOWriteError($$ filename);
The purpose of all this is to facilitate passing the
name of the offending class method to the catch() clause
later on, without having to type it manually within the
throw part. ("logged" evaluates to whitespace if exception
logging is off and to some log-writing magic if exception
logging is on).
Anyway, the '$' character was chosen for the job as
it is unlikely to collide with anything in the source
code (I know, macros are evil). Everything worked fine
until I tried the "-ansi" compiler switch. I was surprised
to see that the compiler complains about the '$' character.
The intel compiler produced an error "expected an identifier"
on the #define line. g++ does not complain in "-ansi" mode,
only after adding "-pedantic" it produces a warning
"$ in identifier or number" on the #define line.
This is surprising me -- shouldn't the preprocessor
have already replaced all occurrences of "$$" with the
macro they represent?
Which compiler behaves in a Standard-compliant manner?
Anyway, can someone tell me what exactly the Standard
says on what characters are allowed in the source code,
both at the before-preprocessor and after-preprocessor
level? I thought you could have anything in your source
files, provided that the preprocessor then replaces
it with something reasonable...
TIA,
- J.