Connecting Tech Pros Worldwide Help | Site Map

bit operations and sequence points

  #1  
Old September 5th, 2006, 08:25 AM
Divick
Guest
 
Posts: n/a
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

  #2  
Old September 5th, 2006, 08:35 AM
Nils O. Selåsdal
Guest
 
Posts: n/a

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
  #3  
Old September 5th, 2006, 03:05 PM
Divick
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
how do increment operations work pai answers 14 February 13th, 2006 03:15 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 11:37 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM