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


Groups > comp.lang.c > #160093

Re: Which side of bitwise OR is evaluated first?

Subject Re: Which side of bitwise OR is evaluated first?
Newsgroups comp.lang.c
References <a21102b2-7c82-40d9-9549-c10a1b77247en@googlegroups.com>
From Richard Damon <Richard@Damon-Family.org>
Message-ID <LfAdI.1200$Qf2.110@fx38.iad> (permalink)
Organization Forte - www.forteinc.com
Date 2021-04-14 07:22 -0400

Show all headers | View raw


On 4/14/21 1:43 AM, Oğuz wrote:
> I wrote this:
> 
>     fp = fopen(optarg, "r");
>     if (!fp || (readfrom(fp), ferror(fp)|fclose(fp)))
>         perror(optarg)
> 
> `readfrom' is a function of type `void' that calls `getline' until it returns -1.
> 
> The reason why I wrote it this way is that I wanted to handle all errors and close the file pointer in a single block. But I'm not sure if `ferror' is guaranteed to be called before `fclose' there, and the standard says once `fclose' is called on `fp', what `ferror(fp)' will do is unspecified or something like that.
> 
> So, should I change this or is it good (except being a bit unreadable)?
> 

C does NOT provide any promise as to the order of evaluation for most
operators.

|| and && and , are the exceptions that come to mind that explicitly
will evaluate the first and then the second, and for || and && the
second is only evaluated if its value is needed, so for || only if the
first value was 'false', and for && only if the first value was 'true'

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


Thread

Which side of bitwise OR is evaluated first? Oğuz <oguzismailuysal@gmail.com> - 2021-04-13 22:43 -0700
  Re: Which side of bitwise OR is evaluated first? Barry Schwarz <schwarzb@delq.com> - 2021-04-14 00:04 -0700
  Re: Which side of bitwise OR is evaluated first? David Brown <david.brown@hesbynett.no> - 2021-04-14 09:42 +0200
    Re: Which side of bitwise OR is evaluated first? Oğuz <oguzismailuysal@gmail.com> - 2021-04-14 00:51 -0700
      Re: Which side of bitwise OR is evaluated first? David Brown <david.brown@hesbynett.no> - 2021-04-14 11:25 +0200
    Re: Which side of bitwise OR is evaluated first? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-14 03:27 -0700
      Re: Which side of bitwise OR is evaluated first? David Brown <david.brown@hesbynett.no> - 2021-04-14 13:28 +0200
        Re: Which side of bitwise OR is evaluated first? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-14 10:31 -0700
          Re: Which side of bitwise OR is evaluated first? David Brown <david.brown@hesbynett.no> - 2021-04-14 19:40 +0200
    Re: Which side of bitwise OR is evaluated first? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-14 10:26 -0700
  Re: Which side of bitwise OR is evaluated first? Richard Damon <Richard@Damon-Family.org> - 2021-04-14 07:22 -0400
    Re: Which side of bitwise OR is evaluated first? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-04-14 07:54 -0700
    Re: Which side of bitwise OR is evaluated first? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-14 14:23 -0400
  Re: Which side of bitwise OR is evaluated first? scott@slp53.sl.home (Scott Lurndal) - 2021-04-14 14:33 +0000
    Re: Which side of bitwise OR is evaluated first? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-14 13:15 -0400
  Re: Which side of bitwise OR is evaluated first? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-04-14 08:06 -0700
    Re: Which side of bitwise OR is evaluated first? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-14 10:34 -0600
      Re: Which side of bitwise OR is evaluated first? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-07-11 00:24 -0700

csiph-web