Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #100582
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: guidelines for pointer check |
| Date | Thu, 29 Dec 2016 16:19:39 -0800 |
| Organization | None to speak of |
| Lines | 39 |
| Message-ID | <lneg0qz2sk.fsf@kst-u.example.com> (permalink) |
| References | <4598b1a6-e647-4327-85d8-23f83198d0c6@googlegroups.com> <ln37h61kky.fsf@kst-u.example.com> <927ce538-f229-4f81-abfc-2b717829665e@googlegroups.com> <C-20161230004512@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx02.eternal-september.org; posting-host="9cde9db04945311bb4638cac08ff52e5"; logging-data="22731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BNV0EZIBqPLz5hj3KKzru" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:QvsNEQRRNo6naM0WgRh1pEpzO04= sha1:Q2SFhBL4MhrZ4P1wBZuVuvgU/u8= |
| Xref | csiph.com comp.lang.c:100582 |
Show key headers only | View raw
ram@zedat.fu-berlin.de (Stefan Ram) writes:
[...]
> Here is a randomly chosen if clause from Nethack:
>
> if (x >= 0 && y >= 0 && x <= (int)max_x_map && y <= (int)max_y_map &&
> (IS_ROCK(tmpmap[y][x]) || IS_DOOR(tmpmap[y][x])))
I have no problem with that. I might group the x and y tests
differently, and I wonder whether the casts are necessary, but
those are trivial points.
More to the point, each of the subexpressions (the operands to && and ||)
is "logically Boolean" -- not necessarily of type _Bool, but
something whose value is logically either false or true, with no
meaningful distinction among different truthy values.
> When someone can't read even a clause as simple as
> »if( p )« or »if( f = fopen( a, b ))«, how could
> he ever work in a real project like Nethack?
There's a big difference between not being able to read some terse
construct and preferring something a bit more verbose. Given that p is
a pointer (and hopefully one with a better name), I know exactly what
if (p)
means, and I don't particularly stumble over it when I see it in code.
Nevertheless, I personally prefer
if (p != NULL)
Why? Because in my view `p` by itself is not logically Boolean (it's a
pointer value), but `p != NULL` is.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
guidelines for pointer check Thiago Adams <thiago.adams@gmail.com> - 2016-12-29 12:53 -0800
Re: guidelines for pointer check Ian Collins <ian-news@hotmail.com> - 2016-12-30 09:58 +1300
Re: guidelines for pointer check Keith Thompson <kst-u@mib.org> - 2016-12-29 13:39 -0800
Re: guidelines for pointer check Thiago Adams <thiago.adams@gmail.com> - 2016-12-29 15:24 -0800
Re: guidelines for pointer check Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-29 19:05 -0500
Re: guidelines for pointer check Thiago Adams <thiago.adams@gmail.com> - 2016-12-30 05:27 -0800
Re: guidelines for pointer check Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-30 14:35 +0000
Re: guidelines for pointer check supercat@casperkitty.com - 2016-12-30 10:38 -0800
Re: guidelines for pointer check Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-02 02:28 -0800
Re: guidelines for pointer check Keith Thompson <kst-u@mib.org> - 2016-12-29 16:19 -0800
Re: guidelines for pointer check Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-29 13:58 -0800
guidelines for pointer check asetofsymbols@gmail.com - 2016-12-30 05:35 -0800
Re: guidelines for pointer check raltbos@xs4all.nl (Richard Bos) - 2017-01-01 10:47 +0000
Re: guidelines for pointer check Noob <root@127.0.0.1> - 2017-01-02 14:19 +0100
Re: guidelines for pointer check David Brown <david.brown@hesbynett.no> - 2017-01-02 14:28 +0100
Re: guidelines for pointer check Noob <root@127.0.0.1> - 2017-01-02 17:35 +0100
Re: Using == operator Noob <root@127.0.0.1> - 2017-01-02 19:03 +0100
Re: Using == operator David Brown <david.brown@hesbynett.no> - 2017-01-02 23:41 +0100
Re: Using == operator Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-02 14:54 -0800
Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-02 15:57 -0800
Re: Using == operator Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2017-01-03 16:31 -0500
Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 14:06 -0800
Re: Using == operator Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-03 14:44 -0800
Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 15:05 -0800
Re: Using == operator Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-04 16:42 +0000
Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 11:46 -0800
Re: Using == operator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-01-03 21:22 -0700
Re: Using == operator supercat@casperkitty.com - 2017-01-03 15:23 -0800
Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 15:30 -0800
Re: Using == operator supercat@casperkitty.com - 2017-01-03 16:02 -0800
Re: Using == operator Keith Thompson <kst-u@mib.org> - 2017-01-03 16:30 -0800
Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 11:26 -0800
Re: Using == operator raltbos@xs4all.nl (Richard Bos) - 2017-01-04 09:55 +0000
Re: Using == operator Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-01-04 16:49 +0000
Re: Using == operator raltbos@xs4all.nl (Richard Bos) - 2017-01-10 01:28 +0000
Re: Using == operator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-01-09 19:12 -0700
Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 09:12 -0800
Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 09:54 -0800
Re: Using == operator raltbos@xs4all.nl (Richard Bos) - 2017-01-03 21:08 +0000
Re: Using == operator Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-15 06:44 -0800
Re: guidelines for pointer check Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2017-01-04 08:54 -0800
Re: guidelines for pointer check Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-14 00:51 -0800
csiph-web