what exactly does the operator |= ???

E

Erick->

hello!!

I was looking at some code in C... and saw this "exotic" operator |=.

first time with it, what exactky does???

thanks in advance.
Erick->
 
R

Richard Heathfield

Erick-> said:
hello!!

I was looking at some code in C... and saw this "exotic" operator |=.

first time with it, what exactky does???

See K&R2, page 50.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
E

Erick->

yeah, that page is about flow control but I don´t think this is the
problem. Is not flow, is assigment.

this was the line:

*cmd |= newcmd;

greetings
Erick->
 
J

james of tucson

Erick- said:
hello!!

I was looking at some code in C... and saw this "exotic" operator |=.

first time with it, what exactky does???


The lvalue on the left is inclusive-OR'd with the expression on the
right, and the result is stored in the lvalue.
 
T

Thierry Chappuis

Erick-> a écrit :
yeah, that page is about flow control but I don´t think this is the
problem. Is not flow, is assigment.

this was the line:

*cmd |= newcmd;

greetings
Erick->

The | operator is the bitwise OR operator. Well, in the same way the
expression x += 1; is equivalent to the x = x +1;, the above mentionned
expression is equivalent to:

*cmd = *cmd | newcmd;

Thierry
 
E

Erick->

thank you!!!!

Thierry said:
Erick-> a écrit :


The | operator is the bitwise OR operator. Well, in the same way the
expression x += 1; is equivalent to the x = x +1;, the above mentionned
expression is equivalent to:

*cmd = *cmd | newcmd;

Thierry
 
N

Nelu

Erick- said:
yeah, that page is about flow control but I don´t think this is the
problem. Is not flow, is assigment.

this was the line:

*cmd |= newcmd;

Pleas don't top-post. I put your reply at the bottom of the
message you replied to and I kept the attribution line (the first
line: Erick-> wrote: ) at the top (so everyone knows who wrote
what and in what order).

|= is like +=, -= and so on. It means that the variable
(actually, lvalue) to the left of the operator will take a value
equal to its original value bitwise-OR-ed with the value on the
right of the operator, e.g. a|=b is equivalent with a=a|b.
 
E

Erick->

Nelu said:
Pleas don't top-post. I put your reply at the bottom of the
message you replied to and I kept the attribution line (the first
line: Erick-> wrote: ) at the top (so everyone knows who wrote
what and in what order).

|= is like +=, -= and so on. It means that the variable
(actually, lvalue) to the left of the operator will take a value
equal to its original value bitwise-OR-ed with the value on the
right of the operator, e.g. a|=b is equivalent with a=a|b.


like this?
 
C

Coos Haak

Op 16 Nov 2006 14:53:42 -0800 schreef Erick->:
yeah, that page is about flow control but I don´t think this is the
problem. Is not flow, is assigment.

this was the line:

*cmd |= newcmd;

(Topposting corrected)
No, page 50 contains '2.10 Assignment Operators and Expressions' which is
just what Richard Heathfield meant.

See the line 'expr1 op = expr2'
 
N

Nelu

Erick- said:
like this?

Yes, you can also snip the signatures. They don't contain any
information that is relevant to the discussion. You can also snip
other stuff that you don't think is relevant to a follow-up. Just
make sure to keep the attributions and follow-up levels untouched
(when you snip) so you don't mangle posters and follow-ups.
 
C

CBFalconer

Erick-> said:
I was looking at some code in C... and saw this "exotic" operator |=.

first time with it, what exactky does???

What does '+' do? What does '+=' do? What does '|' do? Now, what
do you think '|=" does?
 
R

Richard Heathfield

Erick-> said:
yeah, that page is about flow control

No, it isn't. It's entitled "Assignment operators and expressions", and it
answers your question.

Before learning to program, I suggest learning to read.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
B

Bob Martin

in 706142 20061117 080810 Richard Heathfield said:
Erick-> said:


No, it isn't. It's entitled "Assignment operators and expressions", and it
answers your question.

Before learning to program, I suggest learning to read.

If you can't say something useful it would be better to say nothing at all.
 
R

Richard Heathfield

Bob Martin said:
If you can't say something useful it would be better to say nothing at
all.

Indeed. That's why all my replies in this thread (including this one) have
been useful. If you can't see the use of what I have written, that may not
be the fault of the writer.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
M

mark_bluemel

Erick- said:
yeah, that page is about flow control but I don´t think this is the
problem. Is not flow, is assigment.

Richard was refering to Kernighan and Ritchie 2nd Edition, I think you
are probably looking at first edition, where page 46 would be relevant.

|= indicates where the programmer donned a top-hat.
 
E

Erick->

Bob Martin said:


Indeed. That's why all my replies in this thread (including this one) have
been useful. If you can't see the use of what I have written, that may not
be the fault of the writer.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.

do you want to see this book?? with the page NUMBER 50 with the first
line: "Chapter 3 - Control Flow" ???

was the page 46: 2.10 Assignment Operators and Expressions. thanks.
yeah, sure.

sorry for not have the same book and same edition :):). (next time
would be better if you say: read the section 2.10 of K&R book).
 
R

Richard Heathfield

Erick-> said:
do you want to see this book?? with the page NUMBER 50 with the first
line: "Chapter 3 - Control Flow" ???

If that is the case, then it isn't the book I suggested you consult, i.e.
K&R2. Clearly, if you consult some other book, my page reference will not
be valid, but it is certainly valid for the book I suggested.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
K

Keith Thompson

Richard Heathfield said:
Erick-> said:

If that is the case, then it isn't the book I suggested you consult, i.e.
K&R2. Clearly, if you consult some other book, my page reference will not
be valid, but it is certainly valid for the book I suggested.

Are there different printings of K&R2 with different page numbering?

There have been two major editions of K&R (Kernighan & Ritchie, _The C
Programming Language_). The first edition is now mostly of historical
interest. The second edition describes the language standardized by
the 1989 ANSI standard and the 1990 ISO standard. (There are no plans
for a new edition covering the 1999 standard.)

I have both editions, but they're not available at the moment.

Erick, if you're looking at the first edition, you should get a copy
of the second edition.
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top