What is size_t in C?

前端 未结 13 1906
礼貌的吻别
礼貌的吻别 2020-11-22 05:00

I am getting confused with size_t in C. I know that it is returned by the sizeof operator. But what exactly is it? Is it a data type?

Let\'

13条回答
  •  孤城傲影
    2020-11-22 05:09

    If you are the empirical type,

    echo | gcc -E -xc -include 'stddef.h' - | grep size_t
    

    Output for Ubuntu 14.04 64-bit GCC 4.8:

    typedef long unsigned int size_t;
    

    Note that stddef.h is provided by GCC and not glibc under src/gcc/ginclude/stddef.h in GCC 4.2.

    Interesting C99 appearances

    • malloc takes size_t as an argument, so it determines the maximum size that may be allocated.

      And since it is also returned by sizeof, I think it limits the maximum size of any array.

      See also: What is the maximum size of an array in C?

提交回复
热议问题