Kyle R . Burton on Fri, 22 Nov 2002 09:40:08 -0500


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

Re: [PLUG] C #define wizardry question


> assuming ANSI C, you want #x which quotes x, yielding "dog"
> 
> #define set(x) { x##_ = 1; printf("The variable " #x "_ is set.\n"); }

One other minor point: the C compiler automaticly concatenates string
constants that are contiguous.  So the three strings "The variable ", #x 
(which is the result of the macro substitution), and "_ is set.\n" all 
being next to each other will be appended together.

  char *s = "this" " that" " other thing";
  char *help = "This program can be used\n"
               "as a drop-in replacement\n"
               "for your blender, your\n"
               "food processor, and your\n"
               "car's motor.\n";

That is something that impeded my understaning of these kinds of constructs
for a while when I was first learning C.


Kyle

-- 

------------------------------------------------------------------------------
Wisdom and Compassion are inseparable.
        -- Christmas Humphreys
mortis@voicenet.com                            http://www.voicenet.com/~mortis
------------------------------------------------------------------------------
_________________________________________________________________________
Philadelphia Linux Users Group        --       http://www.phillylinux.org
Announcements - http://lists.netisland.net/mailman/listinfo/plug-announce
General Discussion  --   http://lists.netisland.net/mailman/listinfo/plug