Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #401907

Re: why &| dont work and its possible to make it work

From Kaz Kylheku <046-301-5902@kylheku.com>
Newsgroups comp.lang.c
Subject Re: why &| dont work and its possible to make it work
Date 2026-09-10 20:13 +0000
Organization A noiseless patient Spider
Message-ID <20260910130747.60@kylheku.com> (permalink)
References <117mere$3a14a$1@dont-email.me>

Show all headers | View raw


On 2026-09-07, fir <profesor.fir@gmail.com> wrote:
> as i once said i decided to not use && and || as it annoys me (same s == 
> annoys me)
>
> so i will decide to use & | insted but as i not code regullarry today i 
> not yet maneged to test it throughly when it not work and
> if it need big changes in languege to work
>
> i mean one option is that & | should work for BOTH logical and bitwise

The predecessors to the C language had only the bitwise & and | which was
used for testing logical conditions. That's why those operators have
a strangely low precedence.

They work for the purpose, but you have to be fastidiously consistent
about your representation of true; e.g. ensure that true is always 1.

In code like:

  if ((status_reg & FOO_MASK) && (io_reg & BAR_MASK)) ..

we cannot blindly replace && with & because status_reg & FOO_MASK
might produce 0x40, and io_reg & BAR_MASK might produce 0x20.

The & and | operators also do not feature left-to-right sequencing. 
So we cannot replace && with & in code like

  if (ptr != 0 && ptr->foo == bar) ...

Both operands of the & will be evaluated regardless of the value of the
left operand.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

why &| dont work and its possible to make it work fir <profesor.fir@gmail.com> - 2026-09-07 15:39 +0200
  Re: why &| dont work and its possible to make it work bart <bc@freeuk.com> - 2026-09-07 16:42 +0100
    Re: why &| dont work and its possible to make it work fir <profesor.fir@gmail.com> - 2026-09-07 18:14 +0200
    Re: why &| dont work and its possible to make it work Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-09 07:14 +0000
      Re: why &| dont work and its possible to make it work Bonita Montero <Bonita.Montero@gmail.com> - 2026-09-09 11:15 +0200
      Re: why &| dont work and its possible to make it work bart <bc@freeuk.com> - 2026-09-09 11:23 +0100
        Re: why &| dont work and its possible to make it work fir <profesor.fir@gmail.com> - 2026-09-09 13:28 +0200
          Re: why &| dont work and its possible to make it work fir <profesor.fir@gmail.com> - 2026-09-09 14:01 +0200
  Re: why &| dont work and its possible to make it work Bonita Montero <Bonita.Montero@gmail.com> - 2026-09-07 17:49 +0200
    Re: why &| dont work and its possible to make it work fir <profesor.fir@gmail.com> - 2026-09-07 18:22 +0200
    Re: why &| dont work and its possible to make it work Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-09 06:07 +0000
  Re: why &| dont work and its possible to make it work Kaz Kylheku <046-301-5902@kylheku.com> - 2026-09-10 20:13 +0000

csiph-web