Path: csiph.com!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx27.iad.POSTED!not-for-mail X-newsreader: xrn 9.03-beta-14-64bit Sender: scott@dragon.sl.home (Scott Lurndal) From: scott@slp53.sl.home (Scott Lurndal) Reply-To: slp53@pacbell.net Subject: Re: Which side of bitwise OR is evaluated first? Newsgroups: comp.lang.c References: Lines: 25 Message-ID: X-Complaints-To: abuse@usenetserver.com NNTP-Posting-Date: Wed, 14 Apr 2021 14:33:18 UTC Organization: UsenetServer - www.usenetserver.com Date: Wed, 14 Apr 2021 14:33:18 GMT X-Received-Bytes: 1636 Xref: csiph.com comp.lang.c:160095 =?UTF-8?B?T8SfdXo=?= writes: >I wrote this: > > fp =3D 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 retur= >ns -1. > >The reason why I wrote it this way is that I wanted to handle all errors an= >d 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 som= >ething like that. > >So, should I change this or is it good (except being a bit unreadable)? "||" is _not_ a bitwise operator. It's called 'conditional-or', and the semantics include not executing the right-most part if the leftmost part is true. It's more common to write: if (fp && readfrom...)