Pointer to array of unknown bound? [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:39:01

问题:

The following function declaration is accepted by gcc, but not accepted by g++.

void do_something(char (*)[]); 

The error given by g++ is:

error: parameter '<anonymous>' includes pointer to array of unknown bound 'char []' 

I believe that in C, the parameter is converted to char** which is why gcc accepts it fine.

Can I make g++ accept this function somehow?

See example: http://ideone.com/yqvqdB :)

Thanks!

回答1:

The GNU GCC compiler uses non-standard compilant to compile program. Add this flag -std=c99 or -std=iso9899:1999 to compile your program as a standard input and you will get an error.

In standard this will be always accepted as a pointer to an array, so you must provide the lenght of the array as it's required for pointers arithmitics.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!