• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 45  文章 - 129  trackbacks - 0
            <2007年1月>
            31123456
            78910111213
            14151617181920
            21222324252627
            28293031123
            45678910

            專(zhuān)注于C++ P2P STL GP OpenSource等
            Google

            常用鏈接

            留言簿(10)

            隨筆分類(lèi)

            隨筆檔案

            相冊(cè)

            朋友

            • .NET

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            先講#和#@字符:這兩個(gè)比較類(lèi)似:前者是將所代表的東西字符串化,后者是將代表的東西字符化。

            而##可以說(shuō)是個(gè)符號(hào)粘合劑。(Modern C++中用來(lái)做編譯時(shí)期內(nèi)存檢查--2.1節(jié) 就是用了這個(gè)符號(hào))

            #的用法

            The number-sign or "stringizing" operator (#) converts macro parameters (after expansion) to string constants. It is used only with macros that take arguments. If it precedes a formal parameter in the macro definition, the actual argument passed by the macro invocation is enclosed in quotation marks and treated as a string literal. The string literal then replaces each occurrence of a combination of the stringizing operator and formal parameter within the macro definition.

            White space preceding the first token of the actual argument and following the last token of the actual argument is ignored. Any white space between the tokens in the actual argument is reduced to a single white space in the resulting string literal. Thus, if a comment occurs between two tokens in the actual argument, it is reduced to a single white space. The resulting string literal is automatically concatenated with any adjacent string literals from which it is separated only by white space.

            Further, if a character contained in the argument usually requires an escape sequence when used in a string literal (for example, the quotation mark (") or backslash (\) character), the necessary escape backslash is automatically inserted before the character. The following example shows a macro definition that includes the stringizing operator and a main function that invokes the macro:

            #define stringer( x ) printf( #x "\n" )
            
            int main()
            {
                stringer( In quotes in the printf function call\n ); 
                stringer( "In quotes when printed to the screen"\n );   
                stringer( "This: \"  prints an escaped double quote" );
            }

            Such invocations would be expanded during preprocessing, producing the following code:

            int main()
            {
               printf( "In quotes in the printf function call\n" "\n" );
               printf( "\"In quotes when printed to the screen\"\n" "\n" );
               printf( "\"This: \\\" prints an escaped double quote\"" "\n" );
            }

            When the program is run, screen output for each line is as follows:

            In quotes in the printf function call
            
            "In quotes when printed to the screen"
            
            "This: \" prints an escaped double quotation mark"

            Microsoft Specific

            The Microsoft C (versions 6.0 and earlier) extension to the ANSI C standard that previously expanded macro formal arguments appearing inside string literals and character constants is no longer supported. Code that relied on this extension should be rewritten using the stringizing (#) operator.

            END Microsoft Specific

            #@的用法


            Microsoft Specific

            The charizing operator can be used only with arguments of macros. If #@ precedes a formal parameter in the definition of the macro, the actual argument is enclosed in single quotation marks and treated as a character when the macro is expanded. For example:

            #define makechar(x)  #@x

            causes the statement

            a = makechar(b);

            to be expanded to

            a = 'b';

            The single-quotation character cannot be used with the charizing operator.

            END Microsoft Specific

            ##的用法

            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 );
            posted on 2007-01-19 14:03 CPP&&設(shè)計(jì)模式小屋 閱讀(1610) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): 其他

            FeedBack:
            # re: 關(guān)于 ## ,#以及#@的用法 2007-04-21 18:47 heweitykc
            c++整的這么復(fù)雜啊 以后怎么維護(hù)??!  回復(fù)  更多評(píng)論
              
            久久精品国产只有精品66 | 久久免费视频6| 久久精品亚洲AV久久久无码| 99久久99久久精品国产| 亚洲国产精品无码久久久不卡| 久久久中文字幕日本| 国产精品岛国久久久久| 久久精品国产99国产精品亚洲 | 伊人久久大香线蕉亚洲| 久久久久国色AV免费看图片| 97久久综合精品久久久综合| 国产成人久久精品一区二区三区 | 久久天天躁狠狠躁夜夜2020一| 国产女人aaa级久久久级| 国产成人久久AV免费| 久久久国产打桩机| 久久综合一区二区无码| 国产精品久久久99| 国产精品久久久久9999| 久久精品国产亚洲av高清漫画| 精品久久久久成人码免费动漫| 久久男人AV资源网站| 国产精品久久久天天影视香蕉| 国内精品久久久久影院免费| 人人狠狠综合久久88成人| 亚洲精品乱码久久久久久中文字幕 | 久久人做人爽一区二区三区| 久久精品国产99久久香蕉| 91精品国产高清久久久久久国产嫩草| 久久久久国产精品熟女影院| 浪潮AV色综合久久天堂| 亚洲va中文字幕无码久久不卡| 亚洲伊人久久精品影院| 色妞色综合久久夜夜| 久久天天躁狠狠躁夜夜96流白浆| 热re99久久6国产精品免费| 无码人妻精品一区二区三区久久久 | 久久精品亚洲一区二区三区浴池 | 久久精品人妻一区二区三区| 久久精品中文字幕有码| 久久久久亚洲精品无码网址 |