Size of #define values

前端 未结 5 1425
野趣味
野趣味 2021-02-14 04:18

If a value is defined as

#define M_40 40

Is the size the same as a short (2 bytes) or is it as a char (1 byte) or

5条回答
  •  太阳男子
    2021-02-14 05:10

    A #define value has no size, specifically. It's just text substitution. It depends on the context of where (and what) is being substituted.

    In your example, where you use M_40, the compile will see 40, and usually treat it as in int.

    However, if we had:

    void SomeFunc(long);
    
    SomeFunc(M_40);
    

    It will be treated as a long.

提交回复
热议问题