How to determine the length of an array at compile time?

前端 未结 4 1235
一生所求
一生所求 2020-12-18 04:30

Are there macros or builtins that can return the length of arrays at compile time in GCC?

For example:

int array[10];

For which:

4条回答
  •  旧时难觅i
    2020-12-18 05:25

    im not aware of a builtin that does this, but i recently used:

    sizeof(array)/sizeof(array[0])

    to do just that

提交回复
热议问题