This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: String concatenation
- From: Claudio Bley <bley at cs dot uni-magdeburg dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 30 Jul 2003 10:37:17 +0200
- Subject: Re: String concatenation
- References: <LJFHJODJPNKBMEAA@mailcity.com>
On Wed, Jul 30, 2003 at 03:11:36AM -0400, Srivatsan S wrote:
> Hi,
Hi.
> I have the following piece of code which compiles properly with gcc
> version 2.95.3, but gives warnings in 3.2.3. This code piece uses
> token pasting operator in C (##) for string concatenation.
>
>
> #define SETVALUE(x,y) x##y
>
> main()
> {
> char z[20];
> sprintf(z, "%s", SETVALUE("test ", " the program" ));
> printf("z=%s \n", z );
> }
>
> How to compile this successfully on 3.2.3 without warnings?
Remove the `##' -- you don't need it if you want to concatenate
strings. Remember that concatenation works on tokens - it's not a
string concatenation. The macro already simply expands to:
sprintf(z, "%s", "test " " the program");
which IMO has no benefit of using the macro at all. Maybe you
over-simplified your example and your real world application macro
does more complex things which qualify for using that macro?
HTH
--
Claudio Bley ASCII ribbon campaign (")
Debian GNU/Linux user - against HTML email X
http://www.cs.uni-magdeburg.de/~bley/ & vCards / \