变量作为数组大小声明符。 [英] Variables as array size declarators.

查看:55
本文介绍了变量作为数组大小声明符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个包含整数值的变量可以用作整数数组的大小

声明符吗? g ++没有抱怨,但其他

编译器,如Visual C ++ / 6.0,Borland Builder C ++,Turbo C ++和

Dev-C ++ / 4.0,我测试了它拒绝使用变量大小

声明者。

-

Ayaz Ahmed Khan


你永远在,|网站管理员,

网络空间。 | http://fast-ce.org/

_______________________________________________

我在两年前抛弃了Windows for Linux。

生活从未如此好过。

解决方案

" Ayaz Ahmed Khan" <再******* @ myrealbox.com>在消息中写道

news:pa ********************************* @ myrealbox。 com ...

包含整数值的变量是否可以用作整数数组的大小
声明符? g ++没有抱怨,但是其他的编译器,例如Visual C ++ / 6.0,Borland Builder C ++,Turbo C ++和Dev-C ++ / 4.0,我在测试它时拒绝使用变量作为大小
声明者。



不确定,但我认为C允许这个,而g ++允许它作为扩展。

但是,它不是标准的一部分C ++。如果你想使用这种

的东西,请使用std :: vector容器类。它会完全符合您想要的价格。


hth

-

jb


(如果你想通过电子邮件回复,用x替换y)


Ayaz Ahmed Khan写道:
< blockquote class =post_quotes>包含整数值的变量是否可以用作整数数组的大小
声明符?


No.

g ++不抱怨,但其他编译器,如Visual C ++ / 6.0,Borland Builder C ++,Turbo C ++和Dev-C ++ / 4.0,我在测试它时拒绝使用变量作为大小声明器。




你可能在ansi中没有使用g ++等模式。尝试至少使用

以下命令行开关:


-ansi -pedantic -W -Wall


Jakob Bieling写道:


Ayaz Ahmed Khan <再******* @ myrealbox.com>在消息中写道
新闻:pa ********************************* @ myrealbox .com ...

包含整数值的变量可以用作整数数组的大小
声明符吗?



不确定,但是我认为C允许这样,g ++允许它作为扩展。
但是,它不是标准C ++的一部分。如果你想使用这种东西,请使用std :: vector容器类。它将完全符合您的要求。



这些(可变长度数组)在最新标准中添加到C中。

因为那里实际上很少有编译器实现这个标准,实际上以标准兼容的方式实现这种功能是不稳定的。


Brian Rodenborn


Can a variable containing, say, an integer value be used as size
declarator for an array of integers? g++ does not complain, but other
compilers, such as Visual C++/6.0, Borland Builder C++, Turbo C++, and
Dev-C++/4.0, that I tested it on decline to use variables as size
declarators.
--
Ayaz Ahmed Khan

Yours Forever in, | Webmaster,
Cyberspace. | http://fast-ce.org/
_______________________________________________
I ditched Windows for Linux over two years ago.
Life''s never been better since.

解决方案

"Ayaz Ahmed Khan" <re*******@myrealbox.com> wrote in message
news:pa*********************************@myrealbox .com...

Can a variable containing, say, an integer value be used as size
declarator for an array of integers? g++ does not complain, but other
compilers, such as Visual C++/6.0, Borland Builder C++, Turbo C++, and
Dev-C++/4.0, that I tested it on decline to use variables as size
declarators.


Not sure, but I think C allows this and g++ allows it as an extension.
However, it is not part of Standard C++. If you want to use this kind of
stuff, use the std::vector container class. It will do exactly what you
want.

hth
--
jb

(replace y with x if you want to reply by e-mail)


Ayaz Ahmed Khan wrote:

Can a variable containing, say, an integer value be used as size
declarator for an array of integers?
No.
g++ does not complain, but other compilers, such as Visual C++/6.0,
Borland Builder C++, Turbo C++, and Dev-C++/4.0, that I tested it on
decline to use variables as size declarators.



You probably didn''t use g++ in ansi/iso mode. Try to use at least the
following command line switches:

-ansi -pedantic -W -Wall


Jakob Bieling wrote:


"Ayaz Ahmed Khan" <re*******@myrealbox.com> wrote in message
news:pa*********************************@myrealbox .com...

Can a variable containing, say, an integer value be used as size
declarator for an array of integers?


Not sure, but I think C allows this and g++ allows it as an extension.
However, it is not part of Standard C++. If you want to use this kind of
stuff, use the std::vector container class. It will do exactly what you
want.


These (variable-length arrays) were added to C in the latest standard.
As there are few compilers actually implementing that standard yet,
actually having that capability in a standard-compliant way is spotty.

Brian Rodenborn


这篇关于变量作为数组大小声明符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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