Sun Studio 12 Update 1:C++ 用户指南

A.2.123.1 值

value 可以是下列参数:

表 A–31 -xdumpmacros

值 

含义  

[no%]defs

[不] 打印所有宏定义 

[no%]undefs

[不] 打印所有宏取消定义 

[no%]use

[不] 打印关于所用宏的信息 

[no%]loc

[不] 打印 defsundefsuse 的位置(路径名和行号)

[no%]conds

[不] 打印在条件指令中宏的使用信息 

[no%]sys

[不] 打印系统头文件中所有宏的定义、取消定义的宏和宏的使用信息 

%all

设置该选项即表示 -xdumpmacros=defs,undefs,use,loc,conds,sys。该参数最好与 [no%] 形式的其他参数配合使用。例如, -xdumpmacros=%all,no%sys 表示输出中不包含系统头文件宏,但仍提供所有其他宏的信息。

%none

不打印任何宏信息 

这些选项值会累积,因此指定 -xdumpmacros=sys -xdumpmacros=undefs 与指定 -xdumpmacros=undefs,sys 效果相同。


注 –

子选项 loccondssysdefsundefsuse 选项的限定符。使用 loccondssys 本身并不会生成任何结果。例如,使用 -xdumpmacros=loc,conds,sys 不会生成什么结果。


缺省值

如果指定了没有任何参数的 -xdumpmacros,则表示 -xdumpmacros=defs,undefs,sys。如果未指定 -xdumpmacros,则缺省为 -xdumpmacros=%none

示例

如果使用选项 -xdumpmacros=use,no%loc,则使用的每个宏名称只打印一次。但是,如果要了解更多详细信息,请使用选项 -xdumpmacros=use,loc,这样每次使用宏时都会打印位置和宏名称。

例如以下文件 t.c


example% cat t.c
#ifdef FOO
#undef FOO
#define COMPUTE(a, b) a+b
#else
#define COMPUTE(a,b) a-b
#endif
int n = COMPUTE(5,2);
int j = COMPUTE(7,1);
#if COMPUTE(8,3) + NN + MM
int k = 0;
#endif

以下示例显示了使用 defsundefssysloc 参数时文件 t.c 的输出。


example% CC -c -xdumpmacros -DFOO t.c
#define __SunOS_5_9 1
#define __SUNPRO_CC 0x590
#define unix 1
#define sun 1
#define sparc 1
#define __sparc 1
#define __unix 1
#define __sun 1
#define __BUILTIN_VA_ARG_INCR 1
#define __SVR4 1
#define __SUNPRO_CC_COMPAT 5
#define __SUN_PREFETCH 1
#define FOO 1
#undef FOO
#define COMPUTE(a, b) a + b

example% CC -c -xdumpmacros=defs,undefs,loc -DFOO -UBAR t.c
command line: #define __SunOS_5_9 1
command line: #define __SUNPRO_CC 0x590
command line: #define unix 1
command line: #define sun 1
command line: #define sparc 1
command line: #define __sparc 1
command line: #define __unix 1
command line: #define __sun 1
command line: #define __BUILTIN_VA_ARG_INCR 1
command line: #define __SVR4 1
command line: #define __SUNPRO_CC_COMPAT 5
command line: #define __SUN_PREFETCH 1
command line: #define FOO 1
command line: #undef BAR
t.c, line 2: #undef FOO
t.c, line 3: #define COMPUTE(a, b) a + b

以下示例说明了 uselocconds 参数如何报告文件 t.c 中宏的行为:


example% CC -c -xdumpmacros=use t.c
used macro COMPUTE

example% CC -c -xdumpmacros=use,loc t.c
t.c, line 7: used macro COMPUTE
t.c, line 8: used macro COMPUTE

example% CC -c -xdumpmacros=use,conds t.c
used macro FOO
used macro COMPUTE
used macro NN
used macro MM

example% CC -c -xdumpmacros=use,conds,loc t.c
t.c, line 1: used macro FOO
t.c, line 7: used macro COMPUTE
t.c, line 8: used macro COMPUTE
t.c, line 9: used macro COMPUTE
t.c, line 9: used macro NN
t.c, line 9: used macro MM

例如文件 y.c


example% cat y.c
#define X 1
#define Y X
#define Z Y
int a = Z;

以下是使用 -xdumpmacros=use,loc 时有关 y.c 中宏的输出:


example% CC -c -xdumpmacros=use,loc y.c
y.c, line 4: used macro Z
y.c, line 4: used macro Y
y.c, line 4: used macro X

另请参见

要覆盖 -xdumpmacros 的作用域时,请使用 dumpmacros pragma 和 end_dumpmacros pragma。