Pointer and funny business after increment

What if anything is theoretically wrong with this c / C ++ statement:

*memory++ = BIT_MASK & *memory;

Where BIT_MASKis an arbitrary bitmask AND, and memory is a pointer.

The goal was to read the memory cell, the ANDvalue with a mask, save the result in the original location, and then finally increase the pointer to point to the next memory cell.

+5
source share
2 answers

undefined, memory ( , ) , , . ( , , - .)

:

*memory++ &= BIT_MASK;

, , undefined.


C (ISO/IEC 9899: 1999 aka C99), Β§6.5 "", ΒΆ2

, . , . 70)

C. :

undefined,

i = ++i + 1;
a[i++] = i;

i = i + 1;
a[i] = i;

, " C ()" " .

++, , " C".

+15

undefined, memory++ memory .

, C/++ , ++. *memory.

:

*memory = BIT_MASK & *memory;
memory++;

:

*memory++ &= BIT_MASK;

.

+6

All Articles