On 12/31/2012 12: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.


I do not believe this is an issue. The warning is probably just telling you that you tried to initialize a constant unsigned int with a signed value. I don't know if the compiler converts it to 5 or it converts it to the unsigned value that takes form where -5 would take in a signed value. I suggest experimenting with that to make sure that any important behavior dependent on the value works properly. Thought o be honest if they were planning on using a negative value for something important they should have left the variable signed.

Yaro


--
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/50e1e1db.7060...@marupa.net

Reply via email to