Connecting Tech Pros Worldwide Help | Site Map

bit operations and sequence points

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 5th, 2006, 07:25 AM
Divick
Guest
 
Posts: n/a
Default bit operations and sequence points

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, 07:35 AM
Nils O. Selåsdal
Guest
 
Posts: n/a
Default 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, 02:05 PM
Divick
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.