On 31/12/12 01:33 PM, Zbigniew Komarnicki wrote:
Is this OK or is this a bug, when the wariable 'n' is
initializing by negative value? There no any warning.
Is this normal? I know that value -5 is converted
to unsigned but probably this should by printed a warning,
when this is a constant value. What do you think about this?


// prog.cpp
#include<iostream>
using namespace std;

int main()
{
const unsigned int n = -5;

   cout<<  "The variable n is: "<<  n<<  endl;

   return 0;
}

Results:
$ g++ -Wall -W  prog.cpp -o prog
$ ./prog
The variable n is: 4294967291

Thank you.

C and C++ don't protect you from your own mistakes. Do not expect consistent behaviour from "const unsigned int n = -5;". The results will almost certainly differ between 32 bit and 64 bit machines, as well as between x86 and other architectures.



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/50e1ec7e.2010...@rogers.com

Reply via email to