bit operations and sequence points

D

Divick

Hi,
I have written a function which converts from ARGB1555 to RGBA5551
, i.e. changes the position of the msb to lsb by shifting the other
bits. The function is shown below, but I have doubt about the
correctness of this function.

In the operation below, I am using variable ARGB twice in the statement
and there is no sequence point in between those two uses. Thus the
answer is dependent upon the evaluation order of the statement. If ARGB
is shifted left and then used for the & operation then the answer will
not be correct. On my machine and compiler the answer seems right but I
still doubt this function.

void ARGB1555_to_RGBA5551(unsigned short &RGBA, unsigned short ARGB)
{
RGBA = ( (ARGB & (1L << 15)) > 0 ) | (ARGB << 1);
}

Am I right in my reasoning?

Thanks,
Divick
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Divick said:
Hi,
I have written a function which converts from ARGB1555 to RGBA5551
, i.e. changes the position of the msb to lsb by shifting the other
bits. The function is shown below, but I have doubt about the
correctness of this function.

In the operation below, I am using variable ARGB twice in the statement
and there is no sequence point in between those two uses. Thus the
answer is dependent upon the evaluation order of the statement. If ARGB
is shifted left and then used for the & operation then the answer will

It isn't. << yields a new value, ARGB is not altered. You're safe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,048
Members
48,769
Latest member
Clifft

Latest Threads

Top