Re: String concatenation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 / \


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux