0

次のコードはどのように正しくコンパイルされますか?

#include <stdio.h>
#define stringer( x ) printf_s( #x "\n" )
int main() {
stringer( "In quotes when printed to the screen" );   
}

に拡張されるはずではありませんか

printf_s(""In quotes when printed to the screen""\n");

printf_s にネストされた二重引用符があるため、これはエラーですか??

4

3 に答える 3

3

いいえ、#演算子は文字列リテラルを特別に処理します。渡される文字列リテラルの\それぞれをエスケープする必要があります。"正しい展開は次のとおりです。

printf_s( "\"In quotes when printed to the screen\"" "\n" );
于 2012-05-20T20:44:41.977 に答える
2

いいえ、展開されています

printf_s("\"In quotes when printed to the screen\"" "\n");

最終的には

printf_s("\"In quotes when printed to the screen\"\n");

そして印刷する必要があります

"In quotes when printed to the screen"
于 2012-05-20T20:43:42.067 に答える
2

C では、隣接する文字列リテラルが連結されます

隣接する文字列リテラルはコンパイル時に連結されます。これにより、長い文字列を複数の行に分割できます。また、C プリプロセッサの定義とマクロから生成された文字列リテラルをコンパイル時に文字列に追加することもできます。

于 2012-05-20T20:45:13.880 に答える