C: Why isn't size_t a C keyword?

前端 未结 10 2019
鱼传尺愫
鱼传尺愫 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 15:05

    I think that the main reasons that size_t is not a keyword are:

    • there's no compelling reason for it to be. The designers of the C and C++ languages have always preferred to have language features be implemented in the library if possible and reasonable
    • adding keywords to a language can create problems for an existing body of legacy code. This is another reason they are generally resistant to adding new keywords.

    For example, in discussing the next major revision of the C++ standard, Stroustrup had this to say:

    The C++0x improvements should be done in such a way that the resulting language is easier to learn and use. Among the rules of thumb for the committee are:

    ...

    • Prefer standard library facilities to language extensions

    ...

提交回复
热议问题