tags:

views:

210

answers:

5

I am confused. I can not use this on a float? must it be a interger ?? I try to define that as a point but I guess I can not convert float to float *

//global definition
float g_posX = 0.0f;

&g_posX -= 3.03f;
+3  A: 

If you want to subtract from the float then just name the variable and don't take its address:

g_posX -= 3.03f;

Otherwise, &g_posX is an rvalue that you can't assign to it anything.

AraK
+17  A: 

You probably simply want to do this:

float g_posX = 0.0f;
g_posX -= 3.03f;

What your code tries to do is take the address of g_posX and subtract 3.03f from the address. That does not work, for two reasons:

  • The address is not an lvalue: it cannot be assigned to. Assigning to an address would be meaningless. What would it do, move the variable around in memory?
  • Pointer arithmetic can only be done using integers. Fractional addresses do not exist.
Thomas
It would be fun to do bit access like that: `bool* ptr = `
MSalters
Yeah, the thought occurred to me. And of course, if the float is not a multiple of 1/8, it should interpolate between bit values and return fractional bits, or *frits*.
Thomas
A: 

well, &g_posX is a pointer to the float. Pointers are memory addresses and (more or less) intereger. To increase the float, simply remove the &.

ZeissS
A: 

You don't need the the & before g_posX, just do the maths like

g_posX -= 3.03f;
Makis
A: 

increment and decrement operators are only defined for integral data types, not for floating point, double, etc.

Klaus-Dieter Ost
it's not true. As mentioned in many other reponses "g_posX -= 3.03f;" works just fine
Gianluca