[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kernelnewbies
Subject:    RE: A C Language question.
From:       Christine Ames <CAmes () PacificDigital ! com>
Date:       2001-08-30 16:56:42
[Download RAW message or body]

> -----Original Message-----
> From: wanghg [mailto:wanghg@cwc.nus.edu.sg]
> Sent: Thursday, August 30, 2001 4:26 AM
> 
> #define __setup(str, fn) \
> static char __setup_str_##fn[] __initdata = str; \
> static struct kernel_param __setup_##fn 
> __attribute__((unused)) __initsetup 
> = { __setup_str_##fn, fn }
> 
> 
> What is the meaning of "##" here?
> 
<snip>

The following was cut from <blush> the MSVC help system; hope it helps:

Token-Pasting Operator (##)

The double-number-sign or "token-pasting" operator (##), which is sometimes
called the "merging" operator, is used in both object-like and function-like
macros. It permits separate tokens to be joined into a single token and
therefore cannot be the first or last token in the macro definition.

If a formal parameter in a macro definition is preceded or followed by the
token-pasting operator, the formal parameter is immediately replaced by the
unexpanded actual argument. Macro expansion is not performed on the argument
prior to replacement. 

Then, each occurrence of the token-pasting operator in token-string is
removed, and the tokens preceding and following it are concatenated. The
resulting token must be a valid token. If it is, the token is scanned for
possible replacement if it represents a macro name. The identifier
represents the name by which the concatenated tokens will be known in the
program before replacement. Each token represents a token defined elsewhere,
either within the program or on the compiler command line. White space
preceding or following the operator is optional.

This example illustrates use of both the stringizing and token-pasting
operators in specifying program output:

#define paster( n ) printf( "token" #n " = %d", token##n )
int token9 = 9;

If a macro is called with a numeric argument like

paster( 9 );

the macro yields

printf( "token" "9" " = %d", token9 );

which becomes

printf( "token9 = %d", token9 );

[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>RE: A C Language question.</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=2>&gt; From: wanghg [<A \
HREF="mailto:wanghg@cwc.nus.edu.sg">mailto:wanghg@cwc.nus.edu.sg</A>]</FONT> \
<BR><FONT SIZE=2>&gt; Sent: Thursday, August 30, 2001 4:26 AM</FONT> <BR><FONT \
SIZE=2>&gt; </FONT> <BR><FONT SIZE=2>&gt; #define __setup(str, fn) \</FONT>
<BR><FONT SIZE=2>&gt; static char __setup_str_##fn[] __initdata = str; \</FONT>
<BR><FONT SIZE=2>&gt; static struct kernel_param __setup_##fn </FONT>
<BR><FONT SIZE=2>&gt; __attribute__((unused)) __initsetup </FONT>
<BR><FONT SIZE=2>&gt; = { __setup_str_##fn, fn }</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; What is the meaning of &quot;##&quot; here?</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&lt;snip&gt;</FONT>
</P>

<P><FONT SIZE=2>The following was cut from &lt;blush&gt; the MSVC help system; hope \
it helps:</FONT> </P>

<P><FONT SIZE=2>Token-Pasting Operator (##)</FONT>
</P>

<P><FONT SIZE=2>The double-number-sign or "token-pasting" operator (##), which is \
sometimes called the "merging" operator, is used in both object-like and \
function-like macros. It permits separate tokens to be joined into a single token and \
therefore cannot be the first or last token in the macro definition.</FONT></P>

<P><FONT SIZE=2>If a formal parameter in a macro definition is preceded or followed \
by the token-pasting operator, the formal parameter is immediately replaced by the \
unexpanded actual argument. Macro expansion is not performed on the argument prior to \
replacement. </FONT></P>

<P><FONT SIZE=2>Then, each occurrence of the token-pasting operator in token-string \
is removed, and the tokens preceding and following it are concatenated. The resulting \
token must be a valid token. If it is, the token is scanned for possible replacement \
if it represents a macro name. The identifier represents the name by which the \
concatenated tokens will be known in the program before replacement. Each token \
represents a token defined elsewhere, either within the program or on the compiler \
command line. White space preceding or following the operator is optional.</FONT></P>

<P><FONT SIZE=2>This example illustrates use of both the stringizing and \
token-pasting operators in specifying program output:</FONT> </P>

<P><FONT SIZE=2>#define paster( n ) printf( &quot;token&quot; #n &quot; = %d&quot;, \
token##n )</FONT> <BR><FONT SIZE=2>int token9 = 9;</FONT>
</P>

<P><FONT SIZE=2>If a macro is called with a numeric argument like</FONT>
</P>

<P><FONT SIZE=2>paster( 9 );</FONT>
</P>

<P><FONT SIZE=2>the macro yields</FONT>
</P>

<P><FONT SIZE=2>printf( &quot;token&quot; &quot;9&quot; &quot; = %d&quot;, token9 \
);</FONT> </P>

<P><FONT SIZE=2>which becomes</FONT>
</P>

<P><FONT SIZE=2>printf( &quot;token9 = %d&quot;, token9 );</FONT>
</P>

</BODY>
</HTML>


-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic