指向未知边界数组的指针? [英] Pointer to array of unknown bound?

查看:176
本文介绍了指向未知边界数组的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下函数声明被gcc接受,但不被g ++接受。



$ p $ void $ do_something(char(*)[ ]);

g ++给出的错误是:

错误:参数'<匿名>'包含指向未知界限数组的指针'char []'

我相信在C中,参数转换为char **,这就是gcc接受它的原因。



我可以做g ++接受这个函数?



请参阅示例: http:// ideone .com / yqvqdB :)



谢谢!

解决方案

< GNU GCC编译器使用非标准编译器来编译程序。添加此标志 -std = c99 -std = iso9899:1999 以编译您的程序作为标准输入,而您将会得到一个错误。



在标准中,这将始终被接受为指向数组的指针,所以您必须提供数组的长度,因为它是指针算术所需的长度。

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!

解决方案

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.

这篇关于指向未知边界数组的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆