Pointer to array of unspecified size “(*p)[]” illegal in C++ but legal in C

前端 未结 2 1616
滥情空心
滥情空心 2020-11-30 07:28

I just found out that this is illegal in C++ (but legal in C):

#include 
#include 
#define ARRAY_LENGTH(A) (sizeof(A) / sizeof         


        
2条回答
  •  醉话见心
    2020-11-30 08:04

    Dan Saks wrote about this in 1995, during the lead up to C++ standardisation:

    The committees decided that functions such as this, that accept a pointer or reference to an array with unknown bound, complicate declaration matching and overload resolution rules in C++. The committees agreed that, since such functions have little utility and are fairly uncommon, it would be simplest to just ban them. Hence, the C++ draft now states:

    If the type of a parameter includes a type of the form pointer to array of unknown bound of T or reference to array of unknown bound of T, the program is ill-formed.

提交回复
热议问题