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. 7 1281
Jacek Dziedzic wrote:
>
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...
From 2.2 1:
----
The basic source character set consists of 96 characters: the space
character, the control characters representing horizontal tab, vertical
tab, form feed, and new-line, plus the following 91 graphical characters)
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
_ { } [ ] # ( ) < % : ; . ? * + - / ˆ & | ~ ! = , \ " ’
----
$ is obviously not one of them. So, no compiler is required to allow '$'
in identifier names.
--
Clark S. Cox III cl*******@gmail.com
Clark S. Cox III wrote:
From 2.2 1:
----
The basic source character set consists of 96 characters: the space
character, the control characters representing horizontal tab, vertical
tab, form feed, and new-line, plus the following 91 graphical characters)
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
_ { } [ ] # ( ) < % : ; . ? * + - / ˆ & | ~ ! = , \ " ’
----
$ is obviously not one of them. So, no compiler is required to allow '$'
in identifier names.
Thank you. But is the first argument to #define an identifier?
I assumed that the preprocessor merely performs a textual
replacement of its first argument by its second argument,
and that the test for invalid characters only happens
_after_ this replacement. Looks like I was wrong.
thanks,
- J.
Clark S. Cox III wrote:
$ is obviously not one of them. So, no compiler is required to allow '$'
in identifier names.
Of the basic ASCII printables, @ and $ are never used in C or C++
(outside of string/char literals).
Ron Natalie wrote:
Clark S. Cox III wrote:
>$ is obviously not one of them. So, no compiler is required to allow '$' in identifier names.
Of the basic ASCII printables, @ and $ are never used in C or C++
(outside of string/char literals).
Yes, but I'm confused as to what your point was, or why this was in
response to my post.
--
Clark S. Cox III cl*******@gmail.com
Clark S. Cox III wrote:
Ron Natalie wrote:
>Clark S. Cox III wrote:
>>$ is obviously not one of them. So, no compiler is required to allow '$' in identifier names.
Of the basic ASCII printables, @ and $ are never used in C or C++ (outside of string/char literals).
Yes, but I'm confused as to what your point was, or why this was in
response to my post.
Just adding information, I thought people might find it handy
to remember.
Ron Natalie wrote:
Clark S. Cox III wrote:
>Ron Natalie wrote:
>>Clark S. Cox III wrote:
$ is obviously not one of them. So, no compiler is required to allow '$' in identifier names.
Of the basic ASCII printables, @ and $ are never used in C or C++ (outside of string/char literals).
Yes, but I'm confused as to what your point was, or why this was in response to my post.
Just adding information, I thought people might find it handy
to remember.
Yes, in fact that was the reason for selecting '$' as
the character used in this macro-magic. As for '@'
I usually tag all debugs and makeshifts with
// @@@
so that it's easy to grep them out long after I forget
about them.
- J.
On Sun, 22 Oct 2006 14:56:49 +0200, Jacek Dziedzic
<jacek@no_spam.tygrys.no_spam.netwrote in comp.lang.c++:
Clark S. Cox III wrote:
From 2.2 1:
----
The basic source character set consists of 96 characters: the space
character, the control characters representing horizontal tab, vertical
tab, form feed, and new-line, plus the following 91 graphical characters)
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
_ { } [ ] # ( ) < % : ; . ? * + - / ˆ & | ~ ! = , \ " ’
----
$ is obviously not one of them. So, no compiler is required to allow '$'
in identifier names.
Thank you. But is the first argument to #define an identifier?
I assumed that the preprocessor merely performs a textual
replacement of its first argument by its second argument,
and that the test for invalid characters only happens
_after_ this replacement. Looks like I was wrong.
Yes, I'm afraid you were. The first operand to #define is an
identifier, and it has exactly the same characteristics, requirements,
and limitations as any other identifier.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: tony kulik |
last post by:
This code works fine in ie and opera but not at all in Mozilla.
Anybody got a clue as to how to get it right?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script...
|
by: Steven T. Hatton |
last post by:
In the past there have been lengthy discussiions regarding the role of
header files in C++. People have been very adamat about header files
serving as in interface to the implementation. I do...
|
by: Mark F. Haigh |
last post by:
In Andrei Alexandrescu's book _Modern C++ Design_, Chapter 8 ("Object
Factories"), Section 8.4 ("Type Identifiers"), he states:
The only problem that remains is the management of type...
|
by: ehabaziz2001 |
last post by:
Hi,
Till now I do not understand how the null character automatically added
to the end of the string and it is not an element of the string array .
All books said the null character (\0) added...
|
by: Dennis Gearon |
last post by:
Please CC me:
If I create the user 'web_user'
with password 'password'
I can connect using 'psql' just fine.
If I create the user 'D1Khb2g5m7FGk_web_user'
with password 'password'
I CANNOT...
|
by: Andrew Poulos |
last post by:
With the following code I can't understand why this.num keeps
incrementing each time I create a new instance of Foo. For each instance
I'm expecting this.num to alert as 1 but keeps incrementing.
...
|
by: Yevgen Muntyan |
last post by:
Hey,
I was reading C99 Rationale, and it has the following two QUIET CHANGE
paragraphs:
6.5.3.4: "With the introduction of the long long and extended integer
types, the sizeof operator may...
|
by: SRoubtsov |
last post by:
Dear all,
Do you know whether ANSI C (or some other dialects) support the
following:
* a variable name coincides with a type name,
* a structure/union field name coincides with a type name
in...
|
by: tony_in_da_uk |
last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and
got a near-flippant response from someone who clearly didn't take the
time to consider the import. I replied, and it's still not...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |