首页  >  问答  >  正文

c++ - 如何理解带参数的 `#define` ?

part1

  VM_STRUCTS(GENERATE_NONSTATIC_VM_STRUCT_ENTRY,
             GENERATE_STATIC_VM_STRUCT_ENTRY,
             GENERATE_UNCHECKED_NONSTATIC_VM_STRUCT_ENTRY,
             GENERATE_NONSTATIC_VM_STRUCT_ENTRY,
             GENERATE_NONPRODUCT_NONSTATIC_VM_STRUCT_ENTRY,
             GENERATE_C1_NONSTATIC_VM_STRUCT_ENTRY,
             GENERATE_C2_NONSTATIC_VM_STRUCT_ENTRY,
             GENERATE_C1_UNCHECKED_STATIC_VM_STRUCT_ENTRY,
             GENERATE_C2_UNCHECKED_STATIC_VM_STRUCT_ENTRY)

part2

//--------------------------------------------------------------------------------
// VM_STRUCTS
//
// This list enumerates all of the fields the serviceability agent
// needs to know about. Be sure to see also the type table below this one.
// NOTE that there are platform-specific additions to this table in
// vmStructs_<os>_<cpu>.hpp.

#define VM_STRUCTS(nonstatic_field, \
                   static_field, \
                   unchecked_nonstatic_field, \
                   volatile_nonstatic_field, \
                   nonproduct_nonstatic_field, \
                   c1_nonstatic_field, \
                   c2_nonstatic_field, \
                   unchecked_c1_static_field, \
                   unchecked_c2_static_field) \

通常都是

#define type alias

可是这里我们看到是

#define type ___

我画下划线是表示nothing.

如果真的就这么“带人”替换掉,那部就是什么成了上面都没有吗,即便说你把参数都代入了,
但是#define type ___是nothing啊。

这这么理解上面的语法呢?

源码来自jdk8.

阿神阿神2666 天前759

全部回复(1)我来回复

  • 伊谢尔伦

    伊谢尔伦2017-06-05 11:12:42

    帮你找到了完整源码了 http://hg.openjdk.java.net/jd...

    从 50 行到 794 行,这些所有的代码都是一行。

    后面并不是 nothing,而是后面有 700 多行代码。

    回复
    0
  • 取消回复