PDA

View Full Version : problem compiling



mesman00
13th August 2009, 19:19
I am getting a weird compile error:

I am trying to compile the following code:



unsigned short *test;
unsigned addr;

test = (unsigned short*) calloc(1, sizeof(short));

addr = (unsigned) test;

note that the above is just an example to illustrate my problem. This compiles fine in visual studio. however, using qmake and make, I am getting the following error:


error: cast from "short unsigned int*" to "unsigned int" loses precision

does anyone know what might be causing this? i have never encountered this before.

mesman00
13th August 2009, 19:30
I realize if i cast to an 'unsigned long long' the problem is alleviated. it must have to do with the fact that I am on a 64-bit architecture. Still, i do not remember having this problem with g++ (qmake and make) in the past, and it works just find using microsoft compiler.

faldzip
13th August 2009, 19:49
many things works just fine in VS compiler which are errors in g++. And, as I checked one of such situation I had, the g++ is right - because VS compiler compiles code which is WRONG in terms of C++ official standard :] In your case you just lost precission due to address size, which was treated as error and in my opinion it is completly right, because your 'addr' will not contain real address so it would unusable and will lead only to seg fault :]