What happens if I define a 0-size array in C/C++?

后端 未结 7 1407
轻奢々
轻奢々 2020-11-22 03:47

Just curious, what actually happens if I define a zero-length array int array[0]; in code? GCC doesn\'t complain at all.

Sample Program

相关标签:
7条回答
  • 2020-11-22 04:20

    In Standard C and C++, zero-size array is not allowed..

    If you're using GCC, compile it with -pedantic option. It will give warning, saying:

    zero.c:3:6: warning: ISO C forbids zero-size array 'a' [-pedantic]

    In case of C++, it gives similar warning.

    0 讨论(0)
提交回复
热议问题