首頁  >  問答  >  主體

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 天前758

全部回覆(1)我來回復

  • 伊谢尔伦

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

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

    從 50 行到 794 行,這些所有的程式碼都是一行。

    後面不是 nothing,而是後面有 700 多行程式碼。

    回覆
    0
  • 取消回覆