Connecting Tech Pros Worldwide Help | Site Map

bit operations and sequence points

Divick
Guest
 
Posts: n/a
#1: Sep 5 '06
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

Nils O. Selåsdal
Guest
 
Posts: n/a
#2: Sep 5 '06

re: bit operations and sequence points


Divick wrote:
Quote:
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.
Quote:
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
>

--
Nils O. Selåsdal
www.utelsystems.com
Divick
Guest
 
Posts: n/a
#3: Sep 5 '06

re: bit operations and sequence points


Quote:
It isn't. << yields a new value, ARGB is not altered. You're safe.
Oh yes, I forgot the basics. :(

Thanks,
Divick

Closed Thread


Similar C / C++ bytes