"Paavo Helde" <>
> "Balog Pal" <> wrote in news:j62hha$2sej$:
>
>>>>> int main(){ bool const a( 5 ); ::std::cout <<( a == true )<< '\n';
>>> That surprises me -- it's a fairly visible and very dangerous bug,
>>> and I thought the MS compilers were really good these days.
>>
>> Me too. For the record, VS6 does not have this bug. It was picked up
>> on the way up.
It's weird. When I tried it hours ago, it gave 1 for value, 1 for compare,
now using the same code it gives 0 for compare...
> Does VS6 allow
>
> bool const a( 5 );
> char arr[a];
>
> VS2010 accepts the code and makes an array containing 5 elements.
>
> Also interesting:
>
> int main() {
> bool const a( 0xfff );
> const int x=a;
> char arr[x+1];
> }
>
> produces:
> 1>consoletest.cpp(
: error C2466: cannot allocate an array of constant
> size 0
This code in VS5:
#include <iostream>
#include <ostream>
int main()
{
bool const a( 5 );
::std::cout << a <<( a == true )<< '\n';
char c[a];
::std::cout << sizeof(c) << '\n';
bool const b( 0xfff );
const int x=b;
char arr[x+1];
::std::cout << sizeof(arr) << '\n';
return 0;
}
gives
E:\m32\try\t1\t1.cpp(309) : warning C4305: 'initializing' : truncation from
'const int' to 'const bool'
E:\m32\try\t1\t1.cpp(314) : warning C4305: 'initializing' : truncation from
'const int' to 'const bool'
E:\m32\try\t1\t1.cpp(315) : warning C4309: 'initializing' : truncation of
constant value
E:\m32\try\t1\t1.cpp(316) : warning C4101: 'arr' : unreferenced local
variable
E:\m32\try\t1\t1.cpp(311) : warning C4101: 'c' : unreferenced local variable
and prints:
10
5
4096