"Ian Collins" <ian-news@hotmail.com> wrote in message
news:1138181286.151405@drone2-svc-skyt.qsi.net.nz[color=blue]
> Ian Collins wrote:[color=green]
>>
amjain.gzb@gmail.com wrote:
>>[color=darkred]
>>> Greetings,
>>>
>>> I am trying to compile some code on Solaris. I need to compile that
>>> using CC instead of g++.
>>>
>>> Following small program is representation of my problem
>>>
>>> /home/ajain/warningRemoval>cat varsizearray.cpp
>>>
>>> int main()
>>> {
>>> int len = 2*3 ;
>>> int a[len];[/color]
>>
>>
>> This isn't C++, it's gcc specific.
>>
>> Use a vector.
>>[/color]
> <OT>
> I forgot to add that the current CC accepts this if use use const int
> for the size.
> </OT>[/color]
int main()
{
const int len = 2*3;
int a[len];
}
should be accepted by any standard compliant compiler. On the other hand,
the following is non-standard:
int MakeInt()
{
return 6;
}
int main()
{
const int len = MakeInt();
int a[len];
}
According to the standard, array size must be an "integral constant
expression" (section 8.3.4/1). This in turn is defined by section 5.19/1.
"An integral constant-expression can involve only literals (2.13),
enumerators, const variables or static data members of integral or
enumeration types initialized with constant expressions (8.5), non-type
template parameters of integral or enumeration types, and sizeof
expressions. Floating literals (2.13.3) can appear only if they are cast to
integral or enumeration types. Only type conversions to integral or
enumeration types can be used. In particular, except in sizeof expressions,
functions, class objects, pointers, or references shall not be used, and
assignment, increment, decrement, function-call, or comma operators shall
not be used."
--
John Carson