C: Why isn't size_t a C keyword?

前端 未结 10 1995
鱼传尺愫
鱼传尺愫 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

    It does not literally return a value of type size_t since size_t is not a concrete type in itself, but rather a typedef to an unspecified built-in type. Typedef identifiers (such as size_t) are completely equivalent to their respective underlying types (and are converted thereto at compile time). If size_t is defined as an unsigned int on your platform, then sizeof returns an unsigned int when it is compiled on your system. size_t is just a handy way of maintaining portability and only needs to be included in stddef.h if you are using it explicitly by name.

提交回复
热议问题