macro question

Thomas Charron twaffle at gmail.com
Thu Oct 8 13:29:06 EDT 2009


On Thu, Oct 8, 2009 at 1:26 PM, Thomas Charron <twaffle at gmail.com> wrote:
> On Thu, Oct 8, 2009 at 9:36 AM,  <bruce.labitt at autoliv.com> wrote:
>> In a file system_file_ops.c that is in the psocket library there is the
>> statement
>> #define wrap(f) wrap_#f
>> I think this is supposed to do
>> wrap(read)( .... )  ==> wrap_read( .... )
>> Are there circumstances when this does not work?  C89, C99, ???
>  Isn't it supposed to be double #?
> #define wrap(f) wrap_##f

  Confirmed:

The single '#' character means Stringify the following value - a.k.a
to put in double-quotes.
The double '##' characters means to Token-join.

Example File 1:
    #define wrap(f) wrap_#f
    wrap(read)
Preprocessed output (gcc -E <testfile.c>)
    wrap_ "read"

Example File 2:
    #define wrap(f) wrap_##f
    wrap(read)
Preprocessed output (gcc -E <testfile.c>)
    wrap_read

-- 
-- Thomas



More information about the gnhlug-discuss mailing list