C: Why isn't size_t a C keyword?

前端 未结 10 1988
鱼传尺愫
鱼传尺愫 2020-12-28 14:18

sizeof is a C keyword. It returns the size in a type named size_t. However, size_t is not a keyword, but is

10条回答
  •  感情败类
    2020-12-28 14:49

    size_t is not a keyword by necessity. Different architectures often have different sizes for integral types. For example a 64 bit machine is likely to have an unsigned long long as size_t if they didn't decide to make int a 64 bit datatype.

    If you make sizeof a builtin type to the compiler, then it will take away the power to do cross compilation.

    Also, sizeof is more like a magic compile time macro (think c++ template) which explains why it is a keyword instead of defined type.

提交回复
热议问题