linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: value assignment
  2002-09-10 16:58 value assignment Codex
@ 2002-09-10  8:29 ` Mehran Rezaei
  2002-09-10 15:39 ` Stephen Satchell
  1 sibling, 0 replies; 3+ messages in thread
From: Mehran Rezaei @ 2002-09-10  8:29 UTC (permalink / raw)
  To: Codex; +Cc: Linux-C-Programming

Codex wrote:

> pterm.iflag &= ~(IGNBRK | INLCR)
>
> what the hell is '&=' and '~(...)', what does '(...)' does anyway..?,
> wasn't '|' means OR..?

>

Good morning,

So, they are all bitwise operations. & is bitwise AND, | is OR, ~ one's complement.
Do you know what happens when you say i*=5 (i=i*5), the same thing when you say i&=5
(i=i&5).
Say i is 15 then i&=5  is 001111 & 000101 = 000101. ~ is a little bit more
complecated, that is when the size of your variable is important. If i is an integer
(of course the size of i depends on your system, but generally say 32 bits) then ~i
(when i is 15) will be
~0000000000001111=1111111111110000=fff0 Hex.
So long,

Mehran


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: value assignment
  2002-09-10 16:58 value assignment Codex
  2002-09-10  8:29 ` Mehran Rezaei
@ 2002-09-10 15:39 ` Stephen Satchell
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Satchell @ 2002-09-10 15:39 UTC (permalink / raw)
  To: Codex, Linux-C-Programming

At 11:58 PM 9/10/02 +0700, Codex wrote:
>hey i never know what kind assignment is this in C, kindof strange i
>don't get it at all, i somehow know this when doing <termios.h>
>
>pterm.iflag &= ~(IGNBRK | INLCR)
>
>what the hell is '&=' and '~(...)', what does '(...)' does anyway..?,
>wasn't '|' means OR..?

<left> &= <right>  is equivalent to <left> = <left> & <right>  K&R 2nd Ed. 
page 50

| is bit-wise inclusive or.  ibid at page 48

~ is ones complement.  ibid at page 48

(...) form a sub-expression, in which at execution time the stuff inside 
the parens are calculated first.  ibid at page 53.

So, reading the statement from innermost to outermost, it goes like this:
1)  Calculate the inclusive OR of symbols IGNBRK and INLCR.  (Because these 
symbols represent constants and not variables in this context, the compiler 
will perform this operation at compile time.)
2)  Take the ones-complement of the value calculated in (1).  Because the 
above calculation involves only constants, this operation will also be 
performed at compile time.
3)  Calculate the AND of the value calculated in (2) and pterm.iflag.
4)  Store the result of (3) into pterm.iflag.

For single-address stack-oriented machines, the approximate code generated 
would be:

      LoadConstant Compile-time-value-of-(2)
      AND pterm.iflag
      STORE pterm.iflag

If you don't have a copy of Kernighan and Ritchie's _The C Programming 
Language_ (Prentiss-Hall, ISBN 0-13-110362-8) then I suggest you run, not 
walk, to your nearest bookstore and pick up a copy.  Or Amazon if you 
prefer to shop online, at 
http://www.amazon.com/exec/obidos/ASIN/0131103628/qid=1031671821/sr=2-1/ref=sr_2_1/103-8245374-9473450.

There is no excuse for any student trying to pick up the C language lacking 
a copy of this relatively inexpensive textbook, as it still serves as the 
"standard" for practitioners.  (The ANSI standard is almost unreadable.)

Get it, and READ pages 1 through 190.  Several times.  DON'T skim.

Stephen Satchell


^ permalink raw reply	[flat|nested] 3+ messages in thread

* value assignment
@ 2002-09-10 16:58 Codex
  2002-09-10  8:29 ` Mehran Rezaei
  2002-09-10 15:39 ` Stephen Satchell
  0 siblings, 2 replies; 3+ messages in thread
From: Codex @ 2002-09-10 16:58 UTC (permalink / raw)
  To: Linux-C-Programming

Again, Newbie ask

hey i never know what kind assignment is this in C, kindof strange i
don't get it at all, i somehow know this when doing <termios.h>

pterm.iflag &= ~(IGNBRK | INLCR)

what the hell is '&=' and '~(...)', what does '(...)' does anyway..?,
wasn't '|' means OR..?

---------------------------------------------------------------------------
 > Telepon anda sibuk, panggilan tidak bisa masuk.
 > Putar nomor 166 - Info Telkom Memo atau
 > Klik http://www.plasa.com/informasi/telkom-memo/
 ---------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-09-10 16:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-10 16:58 value assignment Codex
2002-09-10  8:29 ` Mehran Rezaei
2002-09-10 15:39 ` Stephen Satchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).