具有可变数量元素的静态数组? [英] static array with variable amount of elements??

查看:79
本文介绍了具有可变数量元素的静态数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在g ++中发现smth奇怪> = 3.3.5 =>

我能够做到

寄存器char buff [outSTDBuffer]; /// /其中

outSTDBuffer是一个变量!!!!


这是gcc中的错误还是c ++的规范发生了变化?在成功编译我的程序后,我注意到这是一个错误!


我应该更改代码。我认为`注册char buff [outSTDBuffer];`

比使用指针更安全如果outSTDBuffer很小!!!

解决方案

Ni @m写​​道:

我发现g ++中的smth奇怪> = 3.3.5 =>
我能够做到
注册char buff [outSTDBuffer]; ////其中
outSTDBuffer是一个变量!!!!

这是gcc中的bug还是c ++的规范发生了变化?我成功编译了我的程序后,我注意到了这个错误!


不符合标准。它是C89的gnu扩展之一(和

C ++)
http://gcc.gnu.org/onlinedocs/gcc/Va...ariable-Length

我应该改变吗代码。




如果您希望它是可移植的,并且符合C ++标准,则为是。


< BLOCKQUOTE>谢谢!是否应该改变它!


Neelesh Bodas D'μà:

不符合标准。它是C89(和/或C ++)的gnu扩展之一
http://gcc.gnu.org/onlinedocs/gcc/Va...ariable-Length



C99支持此功能也是。 :)


I found out smth strange in g++ >= 3.3.5 =>
I was able to do
register char buff[outSTDBuffer];//// where
outSTDBuffer is a variable!!!!

Is it a bug in gcc or specification of c++ changed?? I''ve noticed this
a mistake after successfull compilation of my program!

Should I change the code. I think `register char buff[outSTDBuffer];`
is much safer then use pointers in case if outSTDBuffer is small!!!

解决方案

Ni@m wrote:

I found out smth strange in g++ >= 3.3.5 =>
I was able to do
register char buff[outSTDBuffer];//// where
outSTDBuffer is a variable!!!!

Is it a bug in gcc or specification of c++ changed?? I''ve noticed this
a mistake after successfull compilation of my program!

Not according to standard. Its one of those gnu extensions to C89 (and
C++)
http://gcc.gnu.org/onlinedocs/gcc/Va...ariable-Length
Should I change the code.



Yes if you want it to be portable, and C++ std compliant.


Thanks!!! Is hould change that!


Neelesh Bodas D′μà:

Not according to standard. Its one of those gnu extensions to C89 (and
C++)
http://gcc.gnu.org/onlinedocs/gcc/Va...ariable-Length


C99 supports this feature, too. :)


这篇关于具有可变数量元素的静态数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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