This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 那位熟悉sun forte C++ compiler 7? 有问题请教!#include <iostream>
using namespace std;
const int retint();
int main()
{
const int size = retint();
int arr[size];
return 0;
}
int retint()
{
return 10;
}
这段程序如何修改才能正常运行?谢谢
-oasis(oasis);
2004-2-2
{243}
(#1587651@0)
-
没有这样的语法 arr[size]的,应该改成int* arr = new int[size]
-lionel(Lionel);
2004-2-2
(#1587670@0)
-
gcc 现在支持可变数组下标的,不知Sun Forte 7怎么样。还有个错误,const int retint()
~~~~~
{
return 10;
}
-canadiantire(ct);
2004-2-2
{43}
(#1587716@0)
-
forte 直接调用CC进行编译
-lionel(Lionel);
2004-2-2
(#1587782@0)
-
谢谢二位,原来的程序就是用g++,编译的,不想改动的太多,有没有一个简便的改法?
-oasis(oasis);
2004-2-2
(#1587740@0)
-
forte 里面有很多参数可以调整,试着改改看吧。
-lionel(Lionel);
2004-2-2
(#1587786@0)
-
我老了吗,这样也能编译?int arr[size] 其中size 必须在编译时就能确定大小,换句话说,必须
const int size =10;
int arr[size];
关于gcc能支持变量数组到是第一次听说,可能是它自己的extension吧,98 standard 应该没有这个内容的
-dannyp(Danny);
2004-2-4
{198}
(#1589935@0)
-
gcc 在10年前就已经开始支持可变数组下标了。C99这是Standard,C89我没找到,没有看。BTW, 你甚至可以在循环中初始化变下标的数组!
-canadiantire(ct);
2004-2-4
{44}
(#1590107@0)
-
you are right. GCC supports it.However, dynamic index array wasn't supported by my compiler 10 years ago, and isn't supported by it now. Also check a few popular compiles, including VC7.1, new BC preview (they say they are 100% compatible with the standard), none of them support it. Didn't check other compilers. But I don't get the point, why do people want this feature? why don't they directly go to 'new int [size]' or 'vector<int>' ? I simply don't see the value why it should be in the standard.
-dannyp(Danny);
2004-2-4
{481}
(#1591454@0)
-
As far as I know ...as I read an article by Ritchie, quite a lot of ppl need this feature in scientific calculation area. If i didn't make it wrong, some old languages like FORTRAN or ALGOL support this feature and they are widely used scientific calculations.
-canadiantire(ct);
2004-2-5
{242}
(#1591609@0)
-
questionHere is something confusing: if a array dnymicaly allocated, is it allocated on stack or in heap? If on stack, how big can this array be, especially for scientifc calculation. If it is in heap, then I don't see the benefit.
-dannyp(Danny);
2004-2-7
{225}
(#1595429@0)
-
gcc use iinternal function __alloca to allocate memory for variable length array, seems to be in stack. as to the benefit, i have no idea. :)
-canadiantire(ct);
2004-2-8
(#1596174@0)
-
Thanks.The reason I asked is that I have seen lots of very attractive proposals for new feature to the next standard, such as __closure, property, etc., have failed because they can be done with old feature, although some of the workarounds are really complicate. I am kind of surprise that this less 'obvious' feature has been added into the standard.
-dannyp(Danny);
2004-2-9
{347}
(#1598409@0)