Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Assignment Statement? 1

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
0
0
US
Hello all,

I'm relatively new to C++ (I know enough to read it, and code a little bit), but I'm stumped on a line of code I'm reading.

I'm trying to convert a part of a C++ program to PHP and just don't know what the heck the C++ means. Here's the C++ (a and val are variables):

Code:
( a += (val + e),  a = a << val | a >> (5 - val),  a += val )

I get the left/right shift and all that, but I haven't seen an assignment statement (I'm assuming it's an assignment) that looks like that before.

Thanks.
 
It looks like 3 assignment statements to me:
Code:
a += (val + e);
a = a << val | a >> (5 - val);
a += val;

a += val means: a = a + val

That middle monster is pretty scary... I think they should fire the guy that wrote it.
I believe it is equivalent to this (assuming a is an int):
Code:
int a1 = a << val;
int a2 = a >> (5 - val);
a = a1 | a2;

The | is just ORing the two values together.
 
The original statement was in a define call with parameters so that it could be replaced elsewhere:

Code:
#define my_func(a, val, e) ( a += (val + e),  a = a << val | a >> (5 - val),  a += val )

So it's possible the statement might look more like this:
Code:
a += (val + e),  a = a << val | a >> (5 - val),  a += val;
 
Ah, so the commas just mean multiple assignments then?!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top