Topic: String and character concatenation


Author: scottm@toast.net (Scott)
Date: Wed, 13 Jun 2001 05:20:01 GMT
Raw View
"a" "b" creates "ab". So why doesn't "a" 'b' 'c' create "abc" ? I can't see it
having any other meaning.

This would be massively useful in cases like

#define C_SEP ','
#define C_END '.'
parse("a" C_SEP "bc" C_SEP "de" C_END);

The alternative

parse("a,bc,de.");

is wrong because it embeds into the string things that should be changable from
the #defines alone, and

sprintf(buf, "%s%c%s%c%s%c", "a", C_SEP.....)

commits the unforgivible sin of doing at runtime what the compiler should do...

(I *know* I can just
 #define C_SEP ","
and get the concatenation to work, but then other code ends up using *C_SEP
to access the separator character definition, and that's just.. wrong.)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "Balog Pal" <pasa@lib.hu>
Date: Wed, 13 Jun 2001 14:54:27 GMT
Raw View
"Scott" <scottm@toast.net> wrote in message news:38754.smail.smayo@ziplink.net...

> (I *know* I can just
>  #define C_SEP ","
> and get the concatenation to work, but then other code ends up using *C_SEP
> to access the separator character definition, and that's just.. wrong.)

Make it C_SEP[0] and it will look much better. however I agree with your idea, 'c' could work as a double-quoted "c" in composing string literals.

Paul

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]