Re: Inheritance
On Jun 4, 4:27 pm, Jeff Schwab <j...@schwabcenter.com> wrote:
James Kanze wrote:
On Jun 3, 5:05 pm, Jeff Schwab <j...@schwabcenter.com> wrote:
deepu wrote:
[...]
There are three ways to concatenate strings in C++,
depending on what you mean by "string". If the string
represents a token in the source code, you can use ## in a
macro---formally, this concatenates tokens, not strings, but
in most people's minds, there isn't much different.
I believe you are mistaken there. I cannot answer for "most
people's minds," but I certainly expect most C++ developers to
understand the difference between a string and a token.
One would hope so. Where the ambiguity lies is in the behavior
of the ## operator. In a very real sense, "concatenating a
token" is a non-sense (even if the C and the C++ standard talk
about it). What you are actually concatenating is the original
string representation of the token, e.g.
#define CONCAT2(a,b) a ## b
#define CONCAT(a,b) CONCAT2(a,b)
int CONCAT(name_,0x0A) ;
is required to expand into:
int name_0x0A ;
and not
int name_10 ;
regardless of the internal representation of integer literals,
the actual value, and the fact that 10 and 0x0A are exactly the
same "token" (or more clearly stated, that the strings "10" and
"0x0A" tokenize to exactly the same thing).
I think most programmers think of ## as concatenating "strings",
or at least, the "string representation". I know many
programmers who have been surprised by g++'s error messages
when the results of the concatenation isn't a legal token (which
is undefined behavior according to the standard, but works in
every other compiler I've ever seen). I'll admit that while g++
is applying (or trying to apply) the letter of the law, it
doesn't make sense to me: what is or isn't a token is context
dependent (the "..." after #include *isn't* a string literal,
for example, and if you take the standard literally, cannot be
created by the # operator---although even g++ accepts this).
If you're trying to talk in terms of concatenating tokens, you
have to first define what it means to concatenate a token. Why
is something like "CONCAT(x,5e0)" legal, but "CONCAT(x,5.0)"
not, when they both involve exactly the same tokens?
The popular debate seems to be whether raw arrays of char
should be considered strings.
If he's talking about concatenating string literals (the
only real compile-time "strings"), then just juxtaposing
them is sufficient.
That is true, insofar as we consider character array literals
to be strings. In this sense, I agree that most developers do
consider "hello world" a string, even in C++.
According to the standard, it is a "null-terminated multibyte
string literal", which is a bit verbose for everyday use:-).
It's a string, even if it isn't what I normally think of under
the term "string", when the word is used without more context
when speaking about C++.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34