Zero-length C-array binds to pointer type

前端 未结 6 1216
误落风尘
误落风尘 2020-12-17 20:10

I recently wrote a function template which takes a reference to a C-array:

template 
void foo(T(&c_array)[N]);

6条回答
  •  心在旅途
    2020-12-17 21:05

    As arrays must have greater than zero length, if your compiler erroneously accepts a definition of a zero-sized array then you're "safely" outside of the scope of the language standard. There's no need for you to handle the edge case of N == 0.

    This is true in C++: 8.3.5 [dcl.array]: If the constant-expression (5.19) is present, it shall be an integral constant expression and its value shall be greater than zero.

提交回复
热议问题