Macro definition ARRAY_SIZE

前端 未结 5 2181
借酒劲吻你
借酒劲吻你 2021-02-19 10:55

I encountered the following macro definition when reading the globals.h in the Google V8 project.

// The expression ARRAY_SIZE(a) is a compile-time constant of t         


        
5条回答
  •  一向
    一向 (楼主)
    2021-02-19 11:27

    If sizeof(a) / sizeof(*a) has some remainder (i.e. a is not an integral number of *a) then the expression would evaluate to 0 and the compiler would give you a division by zero error at compile time.

    I can only assume the author of the macro was burned in the past by something that didn't pass that test.

提交回复
热议问题