about *p++ [modified]
-
p1++ = map[((*p++ << 5) & 0x3) | ((*p >> 3) & 0x5)]; <-error, "p++" inoperative
p1++ = map[((*p++ << 7) & 0x5); <- ok, "p++"but vc compiler do it like this
p1++ = map[((*p << 5) & 0x3) | ((*p >> 3) & 0x5)];
p++;
p1++ = map[((*p << 7) & 0x5);
p++;why not
value = map[((*p << 5) & 0x3);
p++;
value |= ((*p >> 3) & 0x5)];
p1++ = value;
p1++ = map[((*p << 7) & 0x5);
p++;how to fix it only use "++"
modified on Sunday, March 7, 2010 6:33 AM
-
p1++ = map[((*p++ << 5) & 0x3) | ((*p >> 3) & 0x5)]; <-error, "p++" inoperative
p1++ = map[((*p++ << 7) & 0x5); <- ok, "p++"but vc compiler do it like this
p1++ = map[((*p << 5) & 0x3) | ((*p >> 3) & 0x5)];
p++;
p1++ = map[((*p << 7) & 0x5);
p++;why not
value = map[((*p << 5) & 0x3);
p++;
value |= ((*p >> 3) & 0x5)];
p1++ = value;
p1++ = map[((*p << 7) & 0x5);
p++;how to fix it only use "++"
modified on Sunday, March 7, 2010 6:33 AM
If you use a pointer (or indeed a value) in an expression, and the expression modifies that value (as you do above with
p++
) then the compiler will not guarantee that the new and old values are used in the order that you expect. This is due to compiler optimisation and is spelled out in the C++ language specification. In the linep1++ = map[((*p++ << 5) & 0x3) | ((*p >> 3) & 0x5)];
if
p
contains 0x100 before this line is executed, then it will contain 0x101 afterwards. However there is no guarantee that it will contain 0x101 in the right half of the OR expression. You should rewrite your expressions to ensure no side effects.txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
p1++ = map[((*p++ << 5) & 0x3) | ((*p >> 3) & 0x5)]; <-error, "p++" inoperative
p1++ = map[((*p++ << 7) & 0x5); <- ok, "p++"but vc compiler do it like this
p1++ = map[((*p << 5) & 0x3) | ((*p >> 3) & 0x5)];
p++;
p1++ = map[((*p << 7) & 0x5);
p++;why not
value = map[((*p << 5) & 0x3);
p++;
value |= ((*p >> 3) & 0x5)];
p1++ = value;
p1++ = map[((*p << 7) & 0x5);
p++;how to fix it only use "++"
modified on Sunday, March 7, 2010 6:33 AM
I'd code-review you back to kindergarden if I was presented code like that.
Watched code never compiles.