Pointer to array of unknown bound? [duplicate]

大憨熊 提交于 2019-12-12 21:28:43

问题


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.



来源:https://stackoverflow.com/questions/20570857/pointer-to-array-of-unknown-bound

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