Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #133735 > unrolled thread
| Started by | skybuck2000@hotmail.com |
|---|---|
| First post | 2018-08-13 12:53 -0700 |
| Last post | 2018-10-10 18:24 -0700 |
| Articles | 20 on this page of 354 — 27 participants |
Back to article view | Back to comp.lang.c
>< swap operator skybuck2000@hotmail.com - 2018-08-13 12:53 -0700
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-08-13 16:05 -0400
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-13 13:46 -0700
Re: >< swap operator Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-08-14 11:19 +0300
Re: >< swap operator skybuck2000@hotmail.com - 2018-08-14 06:16 -0700
Re: >< swap operator bart4858@gmail.com - 2018-08-14 07:50 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-08-14 16:59 +0200
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-08-14 10:46 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-08-14 20:03 +0200
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-08-14 11:37 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-08-14 21:16 +0200
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-14 11:32 -0700
Re: >< swap operator bart4858@gmail.com - 2018-08-14 16:24 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-08-15 11:32 +0200
Re: >< swap operator skybuck2000@hotmail.com - 2018-10-01 07:46 -0700
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 05:20 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 13:58 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 14:08 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 09:16 -0400
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-02 15:35 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 09:43 -0400
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-02 10:51 -0700
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 09:08 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 15:26 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 10:52 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 17:57 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 13:27 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 11:52 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 20:48 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 15:56 -0400
Re: >< swap operator Thiago Adams <thiago.adams@gmail.com> - 2018-10-02 13:05 -0700
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-02 13:26 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 21:36 +0100
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-02 13:47 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-03 11:14 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 16:37 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 22:02 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 17:16 -0400
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-03 11:25 +0200
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-03 10:52 +0100
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-03 14:29 +0200
Re: >< swap operator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-03 05:52 -0700
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-03 21:31 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 16:47 -0400
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-04 03:43 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 22:47 -0400
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-04 04:25 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 20:44 -0700
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-04 11:53 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-04 05:15 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-04 13:48 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-04 10:56 -0400
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-04 17:47 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-04 11:01 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-04 22:15 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-04 16:19 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-04 21:42 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-04 15:01 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-04 23:59 +0100
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-05 09:54 +0200
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-05 18:03 +0100
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-05 21:08 +0200
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-05 20:31 +0100
Re: >< swap operator Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2018-10-05 15:59 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-05 21:18 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-06 03:51 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-06 12:19 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-06 19:49 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-07 12:25 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-07 14:19 +0100
Re: >< swap operator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-07 06:56 -0700
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-07 16:30 +0100
Re: >< swap operator Wouter Verhelst <w@uter.be> - 2018-10-09 13:17 +0200
C idioms (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-09 13:07 +0000
Re: C idioms (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-09 14:27 +0100
Re: C idioms Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-10 00:05 +0100
Re: C idioms Bart <bc@freeuk.com> - 2018-10-10 02:03 +0100
Re: C idioms Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-11 01:05 +0100
Re: C idioms Bart <bc@freeuk.com> - 2018-10-11 02:09 +0100
Re: C idioms Bart <bc@freeuk.com> - 2018-10-11 12:39 +0100
Re: C idioms Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-11 16:24 +0100
Re: C idioms scott@slp53.sl.home (Scott Lurndal) - 2018-10-11 15:55 +0000
Re: C idioms Keith Thompson <kst-u@mib.org> - 2018-10-11 09:42 -0700
Re: C idioms Wouter Verhelst <w@uter.be> - 2018-10-11 19:23 +0200
Re: C idioms jameskuyper@alumni.caltech.edu - 2018-10-11 11:11 -0700
Re: C idioms Keith Thompson <kst-u@mib.org> - 2018-10-11 12:05 -0700
Re: C idioms Bart <bc@freeuk.com> - 2018-10-11 17:53 +0100
Re: C idioms Keith Thompson <kst-u@mib.org> - 2018-10-11 10:38 -0700
Re: C idioms Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-12 00:14 +0100
Re: C idioms Bart <bc@freeuk.com> - 2018-10-11 19:26 +0100
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-09 16:38 +0200
Re: C idioms (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-09 15:23 +0000
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-09 20:31 +0200
Re: C idioms (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-09 20:18 +0100
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-09 22:11 +0200
Re: C idioms (Was: >< swap operator) scott@slp53.sl.home (Scott Lurndal) - 2018-10-09 20:50 +0000
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-09 22:58 +0200
Re: C idioms (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-09 22:34 +0100
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-10 08:10 +0200
Re: C idioms (Was: >< swap operator) jameskuyper@alumni.caltech.edu - 2018-10-09 14:45 -0700
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-10 08:07 +0200
Hmmm... (Was: C idioms (Was: >< swap operator)) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-10 07:56 +0000
Re: Hmmm... (Was: C idioms (Was: >< swap operator)) David Brown <david.brown@hesbynett.no> - 2018-10-10 10:32 +0200
Re: Hmmm... (Was: C idioms (Was: >< swap operator)) Ike Naar <ike@iceland.freeshell.org> - 2018-10-10 13:44 +0000
Re: Hmmm... (Was: C idioms (Was: >< swap operator)) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-10 14:52 +0000
Re: Hmmm... (Was: C idioms (Was: >< swap operator)) Wouter Verhelst <w@uter.be> - 2018-10-10 17:47 +0200
Re: Hmmm... (Was: C idioms (Was: >< swap operator)) David Brown <david.brown@hesbynett.no> - 2018-10-10 17:18 +0200
Re: Hmmm... (Was: C idioms (Was: >< swap operator)) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-10 15:22 +0000
Re: Hmmm... (Was: C idioms (Was: >< swap operator)) David Brown <david.brown@hesbynett.no> - 2018-10-10 23:58 +0200
Re: Hmmm... Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-10-10 07:51 -0600
Re: Hmmm... gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-10 14:53 +0000
Re: Hmmm... David Brown <david.brown@hesbynett.no> - 2018-10-10 17:21 +0200
Re: C idioms (Was: >< swap operator) scott@slp53.sl.home (Scott Lurndal) - 2018-10-10 12:57 +0000
Re: C idioms (Was: >< swap operator) James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-10-10 12:29 -0400
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-11 00:07 +0200
Re: C idioms (Was: >< swap operator) Keith Thompson <kst-u@mib.org> - 2018-10-09 14:50 -0700
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-10 08:13 +0200
Re: C idioms (Was: >< swap operator) scott@slp53.sl.home (Scott Lurndal) - 2018-10-10 12:56 +0000
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-10 15:55 +0200
Re: C idioms (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-10 15:17 +0100
Re: C idioms (Was: >< swap operator) scott@slp53.sl.home (Scott Lurndal) - 2018-10-10 14:49 +0000
Fall-through in switch statements... (Was: C idioms (Was: >< swap operator)) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-10 14:59 +0000
Re: Fall-through in switch statements... (Was: C idioms (Was: >< swap operator)) Bart <bc@freeuk.com> - 2018-10-10 16:09 +0100
Re: Fall-through in switch statements... (Was: C idioms (Was: >< swap operator)) nobody@example.org (Scott) - 2018-10-10 17:29 +0000
Re: C idioms (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-10 16:01 +0100
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-10 17:29 +0200
Re: C idioms (Was: >< swap operator) Wouter Verhelst <w@uter.be> - 2018-10-10 17:55 +0200
Re: C idioms (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-10 17:11 +0100
Re: C idioms Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-10 23:15 +0100
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-11 00:16 +0200
Re: C idioms (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-10 23:23 +0100
Re: C idioms (Was: >< swap operator) Keith Thompson <kst-u@mib.org> - 2018-10-10 16:31 -0700
Re: C idioms (Was: >< swap operator) Keith Thompson <kst-u@mib.org> - 2018-10-10 15:32 -0700
Re: C idioms (Was: >< swap operator) Keith Thompson <kst-u@mib.org> - 2018-10-10 16:24 -0700
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-11 10:52 +0200
Re: C idioms Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-10-10 09:59 -0600
Re: C idioms (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-10 17:26 +0200
Re: C idioms (Was: >< swap operator) scott@slp53.sl.home (Scott Lurndal) - 2018-10-10 14:48 +0000
Return values of fork() (Was: C idioms (Was: >< swap operator)) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-10 14:51 +0000
Re: Return values of fork() (Was: C idioms (Was: >< swap operator)) scott@slp53.sl.home (Scott Lurndal) - 2018-10-10 15:20 +0000
You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-10 15:28 +0000
Re: You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) David Brown <david.brown@hesbynett.no> - 2018-10-11 00:23 +0200
Re: You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) scott@slp53.sl.home (Scott Lurndal) - 2018-10-11 13:22 +0000
Re: You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) David Brown <david.brown@hesbynett.no> - 2018-10-11 15:58 +0200
Re: You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) scott@slp53.sl.home (Scott Lurndal) - 2018-10-11 14:17 +0000
Re: You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) David Brown <david.brown@hesbynett.no> - 2018-10-11 16:42 +0200
Re: You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) Wouter Verhelst <w@uter.be> - 2018-10-11 16:53 +0200
Re: You know that and I know that, but ... (Was: Return values of fork() (Was: C idioms (Was: >< swap operator))) David Brown <david.brown@hesbynett.no> - 2018-10-11 20:11 +0200
Re: Return values of fork() (Was: C idioms (Was: >< swap operator)) David Brown <david.brown@hesbynett.no> - 2018-10-11 00:20 +0200
Re: Return values of fork() (Was: C idioms (Was: >< swap operator)) Keith Thompson <kst-u@mib.org> - 2018-10-10 16:15 -0700
Re: Return values of fork() Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-10-11 14:42 -0600
Re: C idioms Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-10-09 16:18 -0600
Re: C idioms gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-09 22:28 +0000
Re: C idioms scott@slp53.sl.home (Scott Lurndal) - 2018-10-10 12:58 +0000
Re: C idioms (Was: >< swap operator) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-09 07:48 -0700
Re: C idioms Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-09 16:42 +0100
Re: C idioms (Was: >< swap operator) Wouter Verhelst <w@uter.be> - 2018-10-09 19:40 +0200
Re: C idioms (Was: >< swap operator) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-09 12:38 -0700
Re: C idioms (Was: >< swap operator) Wouter Verhelst <w@uter.be> - 2018-10-09 23:41 +0200
Re: C idioms (Was: >< swap operator) Wouter Verhelst <w@uter.be> - 2018-10-09 19:38 +0200
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-07 15:04 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-07 16:37 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-07 16:58 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-07 12:17 -0400
Grammar police! (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-07 20:37 +0000
Re: >< swap operator jameskuyper@alumni.caltech.edu - 2018-10-07 09:31 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-07 18:09 +0100
Re: >< swap operator jameskuyper@alumni.caltech.edu - 2018-10-07 14:05 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-07 22:35 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-08 02:56 +0100
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-08 10:48 +0200
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 12:09 +0100
Re: >< swap operator Ike Naar <ike@iceland.freeshell.org> - 2018-10-08 16:00 +0000
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 17:44 +0100
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-08 10:39 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 20:08 +0100
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-09 11:22 +0200
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-09 09:25 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-09 20:43 +0200
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-09 20:15 +0100
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-09 22:26 +0200
Re: >< swap operator Ike Naar <ike@iceland.freeshell.org> - 2018-10-08 21:09 +0000
Re: >< swap operator David Kleinecke <dkleinecke@gmail.com> - 2018-10-08 15:18 -0700
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-08 07:55 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-09 11:24 +0200
Re: >< swap operator jameskuyper@alumni.caltech.edu - 2018-10-08 07:19 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 16:26 +0100
Re: >< swap operator jameskuyper@alumni.caltech.edu - 2018-10-10 10:59 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 19:53 +0100
Re: >< swap operator James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-10-07 18:00 -0400
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-07 17:10 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 01:25 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-08 02:51 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 11:29 +0100
Re: >< swap operator mark.bluemel@gmail.com - 2018-10-08 04:41 -0700
Re: >< swap operator jameskuyper@alumni.caltech.edu - 2018-10-08 07:56 -0700
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-08 08:36 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 17:34 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-08 21:35 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 22:00 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-09 00:47 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-09 01:11 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-09 02:47 +0100
Re: >< swap operator mark.bluemel@gmail.com - 2018-10-09 00:49 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-09 11:28 +0100
Re: >< swap operator gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-09 13:00 +0000
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-08 10:28 -0700
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-08 10:49 -0700
Re: >< swap operator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-10-07 20:00 -0600
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-06 13:07 -0700
Re: >< swap operator gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-05 23:35 +0000
Re: >< swap operator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-06 03:49 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-06 16:18 +0200
Re: >< swap operator scott@slp53.sl.home (Scott Lurndal) - 2018-10-06 14:48 +0000
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-06 12:53 -0700
Re: >< swap operator scott@slp53.sl.home (Scott Lurndal) - 2018-10-07 16:38 +0000
Re: >< swap operator James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-10-07 15:56 -0400
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-07 16:53 -0700
Re: >< swap operator David Kleinecke <dkleinecke@gmail.com> - 2018-10-07 17:07 -0700
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-07 17:24 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-08 01:30 +0100
Re: >< swap operator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-10-07 19:12 -0600
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-06 18:26 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-06 19:41 +0100
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-06 13:05 -0700
Re: >< swap operator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-07 02:24 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-07 12:41 +0200
100% of the user base... (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-06 00:22 +0000
Re: 100% of the user base... (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-06 01:55 +0100
Re: 100% of the user base... (Was: >< swap operator) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-06 03:58 -0700
Re: 100% of the user base... (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-06 11:51 +0000
Re: 100% of the user base... (Was: >< swap operator) Bart <bc@freeuk.com> - 2018-10-06 13:09 +0100
Re: 100% of the user base... (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-06 05:26 -0700
Re: 100% of the user base... (Was: >< swap operator) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-06 05:40 -0700
Re: 100% of the user base... (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-06 12:46 +0000
Re: 100% of the user base... (Was: >< swap operator) Melzzzzz <Melzzzzz@zzzzz.com> - 2018-10-06 12:46 +0000
Re: 100% of the user base... (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-06 12:49 +0000
Re: 100% of the user base... (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-06 06:27 -0700
Re: 100% of the user base... (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-07 12:47 +0000
Re: 100% of the user base... (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-07 09:03 -0400
Re: 100% of the user base... (Was: >< swap operator) scott@slp53.sl.home (Scott Lurndal) - 2018-10-07 16:47 +0000
Re: >< swap operator Wouter Verhelst <w@uter.be> - 2018-10-05 10:17 +0200
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-05 09:20 +0200
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-05 10:58 +0100
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-05 12:09 +0200
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-05 03:11 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 07:56 -0400
Re: >< swap operator Wouter Verhelst <w@uter.be> - 2018-10-05 14:25 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 08:39 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-05 15:47 +0100
Re: >< swap operator Wouter Verhelst <w@uter.be> - 2018-10-05 17:30 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 11:41 -0400
Re: >< swap operator Wouter Verhelst <w@uter.be> - 2018-10-05 17:56 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 12:00 -0400
Re: >< swap operator Richard Damon <Richard@Damon-Family.org> - 2018-10-05 12:34 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 12:48 -0400
Re: >< swap operator Richard Damon <Richard@Damon-Family.org> - 2018-10-05 13:55 -0400
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-05 11:20 -0700
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 14:45 -0400
Re: >< swap operator Richard Damon <Richard@Damon-Family.org> - 2018-10-05 21:39 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-07 08:51 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-11-25 14:18 -0800
Re: >< swap operator Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-10-05 15:46 +0300
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 06:05 -0700
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 06:16 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-05 15:09 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 10:18 -0400
Re: >< swap operator Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-10-05 17:32 +0300
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 10:34 -0400
Of course it is crazy! (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-05 15:17 +0000
Re: >< swap operator gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-05 18:30 +0000
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 14:48 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 15:06 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-05 13:55 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 06:14 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-05 16:18 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 10:21 -0400
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-05 17:27 +0200
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-05 15:26 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 10:28 -0400
Re: >< swap operator gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-05 14:46 +0000
When pigs fly... (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-05 16:10 +0000
Re: >< swap operator Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-10-05 17:35 +0300
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 10:46 -0400
Re: >< swap operator gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-05 15:15 +0000
6K years??? (Was: >< swap operator) gazelle@shell.xmission.com (Kenny McCormack) - 2018-10-05 13:20 +0000
Re: 6K years??? (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 09:28 -0400
Re: 6K years??? (Was: >< swap operator) Wouter Verhelst <w@uter.be> - 2018-10-05 17:53 +0200
Re: 6K years??? (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 11:56 -0400
Re: 6K years??? (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-05 18:17 +0200
Re: 6K years??? (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 09:21 -0700
Re: 6K years??? (Was: >< swap operator) David Brown <david.brown@hesbynett.no> - 2018-10-05 18:50 +0200
Re: 6K years??? (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 12:52 -0400
Re: 6K years??? (Was: >< swap operator) "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-05 13:05 -0400
Re: 6K years??? (Was: >< swap operator) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-06 03:42 -0700
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-05 15:59 +0200
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-06 03:45 +0100
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-04 11:22 -0700
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-04 20:35 +0100
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-04 13:28 +0100
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-10-04 17:59 +0100
Re: >< swap operator John Bode <jfbode1029@gmail.com> - 2018-10-04 09:56 -0700
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 06:03 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-03 14:37 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 09:51 -0400
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-03 15:39 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 10:05 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 10:09 -0400
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-03 16:22 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 10:29 -0400
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-03 20:52 +0200
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-03 14:57 -0400
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-02 16:06 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-03 00:09 +0100
Re: >< swap operator Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2018-10-02 19:21 -0400
Re: >< swap operator David Brown <david.brown@hesbynett.no> - 2018-10-03 11:21 +0200
Re: >< swap operator Thiago Adams <thiago.adams@gmail.com> - 2018-10-02 13:43 -0700
Re: >< swap operator scott@slp53.sl.home (Scott Lurndal) - 2018-10-02 21:01 +0000
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-02 14:29 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 22:37 +0100
Re: >< swap operator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-03 05:07 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 21:01 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 16:06 -0400
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 21:45 +0100
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 17:09 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 16:11 -0400
Re: >< swap operator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-10-02 16:22 -0400
Re: >< swap operator Thiago Adams <thiago.adams@gmail.com> - 2018-10-02 13:17 -0700
Re: >< swap operator Thiago Adams <thiago.adams@gmail.com> - 2018-10-02 13:24 -0700
Re: >< swap operator scott@slp53.sl.home (Scott Lurndal) - 2018-10-02 15:04 +0000
Re: >< swap operator Niles Rogoff <eternal-september@niles.xyz> - 2018-10-03 18:28 +0000
Re: >< swap operator Thiago Adams <thiago.adams@gmail.com> - 2018-08-14 11:50 -0700
Re: >< swap operator Siri Cruise <chine.bleu@yahoo.com> - 2018-08-14 17:07 -0700
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-15 02:22 -0700
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-15 02:34 -0700
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-15 03:09 -0700
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-15 03:24 -0700
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-15 04:51 -0700
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-15 05:06 -0700
Re: >< swap operator Siri Cruise <chine.bleu@yahoo.com> - 2018-08-15 04:21 -0700
Re: >< swap operator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-08-15 14:43 +0100
Re: >< swap operator fir <profesor.fir@gmail.com> - 2018-08-15 07:08 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-08-15 16:52 +0100
Re: >< swap operator Ike Naar <ike@iceland.freeshell.org> - 2018-08-15 15:51 +0000
Re: >< swap operator John Bode <jfbode1029@gmail.com> - 2018-10-01 14:59 -0700
Re: >< swap operator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-10-02 03:06 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 11:43 +0100
Re: >< swap operator John Bode <jfbode1029@gmail.com> - 2018-10-02 07:27 -0700
Re: >< swap operator Bart <bc@freeuk.com> - 2018-10-02 15:43 +0100
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-02 11:01 -0700
Re: >< swap operator Keith Thompson <kst-u@mib.org> - 2018-10-02 10:54 -0700
Re: >< swap operator Thiago Adams <thiago.adams@gmail.com> - 2018-10-02 12:39 -0700
Re: >< swap operator skybuck2000@hotmail.com - 2018-10-10 18:10 -0700
Re: >< swap operator skybuck2000@hotmail.com - 2018-10-10 18:24 -0700
Page 5 of 18 — ← Prev page 1 … 3 4 [5] 6 7 … 18 Next page →
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2018-10-11 16:24 +0100 |
| Subject | Re: C idioms |
| Message-ID | <87zhvksdz6.fsf@bsb.me.uk> |
| In reply to | #136628 |
Bart <bc@freeuk.com> writes:
> On 11/10/2018 02:09, Bart wrote:
>
>> I think my approach, which I use for user applications, will not be
>> popular here, where every single error possibility must be detected
>> and reported.
That's what your program does. It's just that you define very few
inputs to be error cases. That's a fine approach. In fact it's very
"Unixy".
>> For example, here's an example of a very simple line-oriented text
>> format I use for C projects:
>>
>> module hello.c
>
> ....
>
>> A version using an eof loop in my script language is in the sig. I'll
>> see if I can put together an equally informal C version tomorrow.
>>
>> Notice there is no error checking; the only check is that the file
>> exists (no shown).
> Here is the C code corresponding to that script (but this version is
> case-sensitive). No error checking as promised, apart from checking
> the file can be opened:
>
>
> int main(void) {
> FILE *f;
> char *infile = "/mx/mm.pro";
> enum {size = 1024};
> char line[size];
> char name[size];
> char lastmodule[size];
> char *ptr;
>
> f = fopen(infile,"r");
>
> if (f == NULL) {
> printf("Can' open %s\n", infile);
> exit(1);
> }
>
> strcpy(lastmodule, "(none)");
>
> while (!ateof(f)) {
> readnextline(f, line, size);
> ptr = readname(line, name, size);
> if (strcmp(name, "module") == 0) {
> readname(ptr, lastmodule, size);
> }
> }
>
> fclose(f);
>
> printf("Last module was: %s\n",lastmodule);
>
> }
>
> (This scans a text file looking for the last line roughly matching:
>
> [<white-space>] module <white-space> <filename> [<don't care>])
>
> Is this really that objectionable?
No, it's a reasonable approach to a simple problem. The code is rather
bloated though, and it may accept filenames you don't really mean to
accept (it's not easy for me to say, but it looks wrong).
> If a module name was expected, and it displays "(none)", it means
> something went wrong. The probability that an over-long line is split
> into two by fgets at just the write spot so that:
>
> ...........notmodule file.c
>
> gives a spurious 'module file.c' input for the next line, is ignored.
>
>
> The support headers and functions are here; C requires these occur
> before the main() function:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> int ateof(FILE *f) {
> int c;
> c = fgetc(f);
> if (c == EOF) return 1;
> ungetc(c,f);
> return 0;
> }
>
> int readnextline(FILE *f, char *buffer, int size) {
> *buffer = 0;
> fgets(buffer, size, f);
> }
>
> char* readname(char *ptr, char *dest, int size) {
> int length = 0;
> *dest=0;
> while (1) {
> // can't use switch here as its 'break' clashes with 'while'
> // stupid language ....
> if (*ptr==' ' || *ptr=='\t') {
> ++ptr;
> } else if (*ptr == 0) {
> return ptr;
> } else {
> break;
> }
> }
Most C programmers would probably write
while (*ptr == ' ' || *ptr == '\t')
++ptr;
if (*ptr == 0)
return ptr;
and some would write just two lines:
if (*(ptr += strspn(ptr, " \t")) == 0)
return ptr;
> *dest++ = *ptr++;
> length = 1;
>
> while (1) {
> switch (*ptr) {
> case ',': case '=': case ' ': case '\t':
> *dest = 0;
> return ptr+1;
> case 0:
> *dest = 0;
> return ptr;
> default:
> if (++length < size) {
> *dest++ = *ptr++;
> } else {
> ++ptr;
> }
> }
> }
> return NULL;
> }
Did you intend the input "module ;" to report "Last module was: ;" but
"module x;" to report "Last module was: x"? It seems wrong in that
commas, semicolons, equals, spaces and tabs appear to be designed as
filename terminators.
Given the subject line, I think the thread should include how this
program might be written by a C programmer. Here's one way... 23 lines
vs. 91.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
unsigned n_seen = 0;
char *infile = argc > 1 ? argv[1] : "/mx/mm.pro";
FILE *f = fopen(infile, "r");
if (f) {
enum {size = 1024};
char line[size];
char lastmodule[size] = "(none)";
while (fgets(line, sizeof line, f))
n_seen +=
sscanf(line, " module%*[ \t]%[^;=, \t]", lastmodule) == 1;
fclose(f);
printf("Last module was: %s\n", lastmodule);
}
else printf("Can't open %s\n", infile);
return n_seen ? EXIT_SUCCESS : EXIT_FAILURE;
}
Since it can be done at no cost, I've made the program more flexible in
what file it processes, and I signal the only real error case (there
being no "module" line) to the system.
Of course, this does not accept lone ";", "," or "=" as a module name.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2018-10-11 15:55 +0000 |
| Subject | Re: C idioms |
| Message-ID | <eoKvD.95780$fE2.59582@fx30.iad> |
| In reply to | #136655 |
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>Bart <bc@freeuk.com> writes:
>> int main(void) {
>> FILE *f;
>> char *infile = "/mx/mm.pro";
Bad programmer! Pass it in to main as an argument.
>> enum {size = 1024};
>> char line[size];
>> char name[size];
>> char lastmodule[size];
Fixes sizes always come back to byte you.
>> char *ptr;
>>
>> f = fopen(infile,"r");
>>
>> if (f == NULL) {
>> printf("Can' open %s\n", infile);
Why can't you open it?
printf("Unable to open '%s':%s\n", infile, strerror(errno));
>> char* readname(char *ptr, char *dest, int size) {
>> int length = 0;
>> *dest=0;
>> while (1) {
>> // can't use switch here as its 'break' clashes with 'while'
>> // stupid language ....
>> if (*ptr==' ' || *ptr=='\t') {
>> ++ptr;
>> } else if (*ptr == 0) {
>> return ptr;
>> } else {
>> break;
>> }
>> }
>
>Most C programmers would probably write
>
> while (*ptr == ' ' || *ptr == '\t')
> ++ptr;
Or better:
while (isspace(*ptr)) ptr++;
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2018-10-11 09:42 -0700 |
| Subject | Re: C idioms |
| Message-ID | <lnbm80xwny.fsf@kst-u.example.com> |
| In reply to | #136657 |
scott@slp53.sl.home (Scott Lurndal) writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>Bart <bc@freeuk.com> writes:
>
>>> int main(void) {
>>> FILE *f;
>>> char *infile = "/mx/mm.pro";
>
> Bad programmer! Pass it in to main as an argument.
It depends. If it's passed as an argument, then whoever runs the
program has to know that "/mx/mm.pro" is the right name. There could be
an overridable default.
[...]
>>> char *ptr;
>>>
>>> f = fopen(infile,"r");
>>>
>>> if (f == NULL) {
>>> printf("Can' open %s\n", infile);
>
> Why can't you open it?
>
> printf("Unable to open '%s':%s\n", infile, strerror(errno));
The standard doesn't require fopen() to set errno on failure (though I
think it does on most systems).
[...]
>>Most C programmers would probably write
>>
>> while (*ptr == ' ' || *ptr == '\t')
>> ++ptr;
>
> Or better:
>
> while (isspace(*ptr)) ptr++;
Or better:
> while (isspace((unsigned char)*ptr)) ptr++;
If plain char is signed and *ptr happens to be negative (and not equal
to EOF), the isspace() call has undefined behavior.
--
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"
[toc] | [prev] | [next] | [standalone]
| From | Wouter Verhelst <w@uter.be> |
|---|---|
| Date | 2018-10-11 19:23 +0200 |
| Subject | Re: C idioms |
| Message-ID | <uhd49f-cnb.ln1@gangtai.home.grep.be> |
| In reply to | #136663 |
On 11/10/18 18:42, Keith Thompson wrote: > Or better: > >> while (isspace((unsigned char)*ptr)) ptr++; > > If plain char is signed and *ptr happens to be negative (and not equal > to EOF), the isspace() call has undefined behavior. > Are you sure about that? That seems odd. Why would isspace(), when given a negative value on an architecture where char is signed, have undefined behaviour?
[toc] | [prev] | [next] | [standalone]
| From | jameskuyper@alumni.caltech.edu |
|---|---|
| Date | 2018-10-11 11:11 -0700 |
| Subject | Re: C idioms |
| Message-ID | <e0d1a748-aedb-4e9b-90fd-30e9597aa97e@googlegroups.com> |
| In reply to | #136672 |
On Thursday, October 11, 2018 at 1:58:03 PM UTC-4, Wouter Verhelst wrote: > On 11/10/18 18:42, Keith Thompson wrote: > > Or better: > > > >> while (isspace((unsigned char)*ptr)) ptr++; > > > > If plain char is signed and *ptr happens to be negative (and not equal > > to EOF), the isspace() call has undefined behavior. > > > > Are you sure about that? That seems odd. Why would isspace(), when given > a negative value on an architecture where char is signed, have undefined > behaviour? 123456789012345678901234567890123456789012345678901234567890123456789012 Because the standard specifies that "The header <ctype.h> declares several functions useful for classifying and mapping characters.198) In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined." (7.4p1).
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2018-10-11 12:05 -0700 |
| Subject | Re: C idioms |
| Message-ID | <lnr2gwwbh3.fsf@kst-u.example.com> |
| In reply to | #136672 |
Wouter Verhelst <w@uter.be> writes:
> On 11/10/18 18:42, Keith Thompson wrote:
>> Or better:
>>
>>> while (isspace((unsigned char)*ptr)) ptr++;
>>
>> If plain char is signed and *ptr happens to be negative (and not equal
>> to EOF), the isspace() call has undefined behavior.
>>
>
> Are you sure about that? That seems odd. Why would isspace(), when given
> a negative value on an architecture where char is signed, have undefined
> behaviour?
Yes, I'm sure, and yes, it's odd and annoying. It's for historical
reasons. (I think early C programmers just assumed either that
char would be unsigned, or that all input characters would be ASCII
and therefore non-negative).
I'd like to see it fixed in a future edition of the standard.
I'd like the behavior of isspace() to be well defined for any
argument in the range CHAR_MIN .. UCHAR_MAX (typically -128 to +255).
One possible problem with such a change is that the is*() functions
have locale-specific behavior. If EOF is -1 (as it almost always
is), then isalpha(-1) returns 0 -- but in a Latin-1 locale, (char)-1
could represent LATIN SMALL LETTER Y WITH DIAERESIS (0xff). I doubt
that there's much code that depends on the behavior of the is*()
or to*() functions with an argument of EOF, but there could be some.
Meanwhile, that annoying (unsigned char) cast is necessary if you
want to be safe.
--
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"
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2018-10-11 17:53 +0100 |
| Subject | Re: C idioms |
| Message-ID | <heLvD.91150$NK5.26845@fx02.am4> |
| In reply to | #136657 |
On 11/10/2018 16:55, Scott Lurndal wrote:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> Bart <bc@freeuk.com> writes:
>
>>> int main(void) {
>>> FILE *f;
>>> char *infile = "/mx/mm.pro";
>
> Bad programmer! Pass it in to main as an argument.
>
>
>>> enum {size = 1024};
>>> char line[size];
>>> char name[size];
>>> char lastmodule[size];
>
> Fixes sizes always come back to byte you.
So do elaborate expanding buffer schemes where they are full of bugs, or
when you run out of memory to accommodate some 20GB binary file on one line.
>>> char *ptr;
>>>
>>> f = fopen(infile,"r");
>>>
>>> if (f == NULL) {
>>> printf("Can' open %s\n", infile);
>
> Why can't you open it?
>
> printf("Unable to open '%s':%s\n", infile, strerror(errno));
>
Usually because it can't find it: either file does not exist, or the
path doesn't.
But I don't remember applications ever going into much more detail than
reporting the error.
However I do remember many programs saying the can't find or open a
file, but without saying /which/ file they are trying to open, or not
showing the full filespec it has tried.
This is one thing I always try and get right.
--
bart
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2018-10-11 10:38 -0700 |
| Subject | Re: C idioms |
| Message-ID | <ln7eioxu28.fsf@kst-u.example.com> |
| In reply to | #136657 |
scott@slp53.sl.home (Scott Lurndal) writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>>Bart <bc@freeuk.com> writes:
>
>>> int main(void) {
>>> FILE *f;
>>> char *infile = "/mx/mm.pro";
>
> Bad programmer! Pass it in to main as an argument.
It depends. If it's passed as an argument, then whoever runs the
program has to know that "/mx/mm.pro" is the right name. There could be
an overridable default.
[...]
>>> char *ptr;
>>>
>>> f = fopen(infile,"r");
>>>
>>> if (f == NULL) {
>>> printf("Can' open %s\n", infile);
>
> Why can't you open it?
>
> printf("Unable to open '%s':%s\n", infile, strerror(errno));
The standard doesn't require fopen() to set errno on failure (though I
think it does on most systems, and POSIX requires it).
[...]
>>Most C programmers would probably write
>>
>> while (*ptr == ' ' || *ptr == '\t')
>> ++ptr;
>
> Or better:
>
> while (isspace(*ptr)) ptr++;
Or better:
> while (isspace((unsigned char)*ptr)) ptr++;
If plain char is signed and *ptr happens to be negative (and not equal
to EOF), isspace(*ptr) call has undefined behavior.
--
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"
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2018-10-12 00:14 +0100 |
| Subject | Re: C idioms |
| Message-ID | <877eionkie.fsf@bsb.me.uk> |
| In reply to | #136657 |
scott@slp53.sl.home (Scott Lurndal) writes: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: <snip> >>Most C programmers would probably write >> >> while (*ptr == ' ' || *ptr == '\t') >> ++ptr; > > Or better: > > while (isspace(*ptr)) ptr++; Except that does not do the same thing, and I wanted to focus on "how to write X" rather than say "better write Y". (Not to mention that I didn't want to get into the (unsigned char) issue!) -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2018-10-11 19:26 +0100 |
| Subject | Re: C idioms |
| Message-ID | <KBMvD.33218$1C7.5318@fx38.am4> |
| In reply to | #136655 |
On 11/10/2018 16:24, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:
> Given the subject line, I think the thread should include how this
> program might be written by a C programmer.
Even C programmers might want to write building block functions.
Here's one way... 23 lines
> vs. 91.
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char **argv) {
> unsigned n_seen = 0;
> char *infile = argc > 1 ? argv[1] : "/mx/mm.pro";
> FILE *f = fopen(infile, "r");
>
> if (f) {
> enum {size = 1024};
> char line[size];
> char lastmodule[size] = "(none)";
>
> while (fgets(line, sizeof line, f))
> n_seen +=
> sscanf(line, " module%*[ \t]%[^;=, \t]", lastmodule) == 1;
> fclose(f);
>
> printf("Last module was: %s\n", lastmodule);
> }
> else printf("Can't open %s\n", infile);
> return n_seen ? EXIT_SUCCESS : EXIT_FAILURE;
> }
>
> Since it can be done at no cost, I've made the program more flexible in
> what file it processes, and I signal the only real error case (there
> being no "module" line) to the system.
>
> Of course, this does not accept lone ";", "," or "=" as a module name.
Yes you can write a tighter loop using lower level functions. My version
attempted to have some of the abstraction that was present in the
scripted version.
That also lends itself to be upgraded later without affecting the
'user-code' represented by the loop in main(). For example I can decide
to make readnextline() deal with over-long lines.
Or I can change the set of separators or terminators used between chunks
of characters on the input line. (Old code seemed to use " ,;\t=", the
more recent code I glimpsed at only appears to use " ,\t=" so it could
just have been an omission.)
(In practice you would apply filename validation to the result of
readname() if it was important the filename was correct.)
Doing it this way also allows quoted names to be added without changing
user-code (as the script also allows, but I didn't add it to the C version).
--
bart
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2018-10-09 16:38 +0200 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <ppiei3$n9l$1@dont-email.me> |
| In reply to | #136477 |
On 09/10/18 15:07, Kenny McCormack wrote:
> In article <pbfu8f-mil.ln1@gangtai.home.grep.be>,
> Wouter Verhelst <w@uter.be> wrote:
>> On 10/7/18 3:56 PM, Malcolm McLean wrote:
>>> On Sunday, October 7, 2018 at 2:19:55 PM UTC+1, Ben Bacarisse wrote:
>>>
>>>> C needs expression statements -- statements formed from an expression
>>>> and a semicolon -- to work. There is no reason to keep denying this
>>>> distinction.
>>>>
>>> We could easily enough declare that an assignment doesn't yield a value.
>>> That would break some C code in a way that is difficult to simply fix,
>>> but arguably such code is badly written anyway and doesn't deserve to
>>> be supported.
>>
>> Whoa.
>>
>> if((pid = fork()) < 0) {
>> // error handling
>> } else if(pid == 0) {
>> // child code
>> } else {
>> // parent code
>> }
>>
>> I think that's not badly written at all, and uses the value of the
>> assignment expression.
>
> That's a common idiom, but it is not really necessary. I'm sure many in
> the "keep it clear - even to morons" crowd would argue that it should be
> written:
>
> pid = fork();
> switch (pid) {
> ...
> }
>
I don't think the first version is unclear, but I don't see any
significant advantages to it compared to the second one (assuming that
is corrected to use "if" rather than "switch").
Combining assignment and tests can be useful if it saves repetition of
code, or keeps the scope of local variables tighter - that example does
neither.
> What's less clear is when you're doing a "while" loop. Then you want to be
> able to do:
>
> while ((c = getwhatver()) != EOF) {
> ...
> }
>
> Here it is less clear how to re-write this without using the embedded
> assignment.
Yes, re-writing this code without using the result of the assignment
gets a bit ugly. You have something like:
while (true) {
int c = getwhatver();
if (c == EOF) break;
...
}
That keeps the local variable more local, which is good, but gives you
an infinite loop with a break rather than a clear loop condition, which
is not good.
[toc] | [prev] | [next] | [standalone]
| From | gazelle@shell.xmission.com (Kenny McCormack) |
|---|---|
| Date | 2018-10-09 15:23 +0000 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <ppih4t$ost$1@news.xmission.com> |
| In reply to | #136482 |
In article <ppiei3$n9l$1@dont-email.me>, David Brown <david.brown@hesbynett.no> wrote: ... >I don't think the first version is unclear, but I don't see any... Because you're not a moron. You're many things, but a moron you're not. ... >is corrected to use "if" rather than "switch"). No. Switch is better. -- A pervert, a racist, and a con man walk into a bar... Bartender says, "What will you have, Donald!"
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2018-10-09 20:31 +0200 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <ppis55$hgo$1@dont-email.me> |
| In reply to | #136486 |
On 09/10/18 17:23, Kenny McCormack wrote: > In article <ppiei3$n9l$1@dont-email.me>, > David Brown <david.brown@hesbynett.no> wrote: > ... >> I don't think the first version is unclear, but I don't see any... > > Because you're not a moron. You're many things, but a moron you're not. > Why, thank you. > >> is corrected to use "if" rather than "switch"). > > No. Switch is better. > A switch is better when a switch is appropriate. It won't work here, so it is not better. We are branching on a value being less than, equal to or greater than zero - a switch won't do that.
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2018-10-09 20:18 +0100 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <Z97vD.33513$621.32461@fx06.am4> |
| In reply to | #136495 |
On 09/10/2018 19:31, David Brown wrote: > On 09/10/18 17:23, Kenny McCormack wrote: >> In article <ppiei3$n9l$1@dont-email.me>, >> David Brown <david.brown@hesbynett.no> wrote: >> ... >>> I don't think the first version is unclear, but I don't see any... >> >> Because you're not a moron. You're many things, but a moron you're not. >> > > Why, thank you. > >> >>> is corrected to use "if" rather than "switch"). >> >> No. Switch is better. >> > > A switch is better when a switch is appropriate. It won't work here, so > it is not better. We are branching on a value being less than, equal to > or greater than zero - a switch won't do that. Then a lightweight sign function is used. A properly lightweight one, not one designed for floating point, that involves copysign(), or that uses the new spaceship operator. -- bart
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2018-10-09 22:11 +0200 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <ppj21k$p71$1@dont-email.me> |
| In reply to | #136501 |
On 09/10/18 21:18, Bart wrote: > On 09/10/2018 19:31, David Brown wrote: >> On 09/10/18 17:23, Kenny McCormack wrote: >>> In article <ppiei3$n9l$1@dont-email.me>, >>> David Brown <david.brown@hesbynett.no> wrote: >>> ... >>>> I don't think the first version is unclear, but I don't see any... >>> >>> Because you're not a moron. You're many things, but a moron you're not. >>> >> >> Why, thank you. >> >>> >>>> is corrected to use "if" rather than "switch"). >>> >>> No. Switch is better. >>> >> >> A switch is better when a switch is appropriate. It won't work here, >> so it is not better. We are branching on a value being less than, >> equal to or greater than zero - a switch won't do that. > > Then a lightweight sign function is used. > > A properly lightweight one, not one designed for floating point, that > involves copysign(), or that uses the new spaceship operator. > These would all let you use "switch" instead of "if". Switch will also work if the negative value on error is always a known, fixed value (the "greater than 0" branch would be the default clause). Whether "switch" is better than "if" for this sort of thing is another matter. "if" seems simpler and clearer to me in this case.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2018-10-09 20:50 +0000 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <Zv8vD.110260$OM2.43558@fx37.iad> |
| In reply to | #136495 |
David Brown <david.brown@hesbynett.no> writes:
>On 09/10/18 17:23, Kenny McCormack wrote:
>> In article <ppiei3$n9l$1@dont-email.me>,
>> David Brown <david.brown@hesbynett.no> wrote:
>> ...
>>> I don't think the first version is unclear, but I don't see any...
>>
>> Because you're not a moron. You're many things, but a moron you're not.
>>
>
>Why, thank you.
>
>>
>>> is corrected to use "if" rather than "switch").
>>
>> No. Switch is better.
>>
>
>A switch is better when a switch is appropriate. It won't work here, so
>it is not better. We are branching on a value being less than, equal to
>or greater than zero - a switch won't do that.
>
$ grep fork */cmd/*/*.c | grep switch
common/cmd/bnu/ct.c: switch(_Pid = fork()) {
common/cmd/bnu/permld.c: switch( pid = (id_t) fork() ) {
common/cmd/bnu/uucp.c: switch (chpid = fork()) {
common/cmd/bnu/uux.c: switch (child = fork()) {
common/cmd/cr1/keymaster.c: switch (ret = fork()) {
common/cmd/creatiadb/creatiadb.c: switch (fork()) {
common/cmd/dfsck/dfsck.c: switch(pid1 = fork()) {
common/cmd/dfsck/dfsck.c: switch(pid2 = fork()) {
common/cmd/find/find.c: switch (cmdproc[proc].pid = fork())
common/cmd/fs.d/ff.c: switch(pid=fork()) {
common/cmd/fs.d/ncheck.c: switch(pid = fork()) {
common/cmd/inetinst/pkgcat.c: switch(pid=fork()) {
common/cmd/keyserv/detach.c: switch (fork()) {
common/cmd/keyserv/update.c: switch (pid = vfork()) {
common/cmd/keyserv/update.c: switch (pid = fork()) {
common/cmd/mailx/names.c: switch (fork()) {
common/cmd/merge_ipx/mipxadm.c: switch(fork()) {
common/cmd/pseudo/pseudo.c: switch (pid = fork()) {
common/cmd/pseudo/pseudo.c: switch (fork()) {
common/cmd/rpcbind/rpcbind.c: switch (fork()) {
common/cmd/rpcgen/rpc_main.c: switch (fork()) {
common/cmd/sdiff/sdiff.c: switch(pid=fork()){
common/cmd/tar/tar.c: switch (child_pid = fork()) {
common/cmd/truss/main.c: switch (fork()) {
common/cmd/xargs/xargs.c: switch (child = fork()) {
common/cmd/ypcmd/openchild.c: switch (pid = fork()) {
i386/cmd/fs.d/df.c: switch(pid = fork()) {
common/cmd/find/find.c:
switch (cmdproc[proc].pid = fork())
{
case -1:
return(0);
case 0:
if (fp && fileno(fp) != usrfd)
{
(void)close(usrfd);
if (dup2(fileno(fp), usrfd) != usrfd)
_exit(CMDERR);
(void)close(fileno(fp));
}
(void)close(cmdfd);
if (dup2(pio[cmdfd], cmdfd) != cmdfd)
_exit(CMDERR);
(void)close(pio[cmdfd]);
(void)close(pio[usrfd]);
{
int privid;
privid = secsys(ES_PRVID, 0);
if (privid < 0 || privid != getuid())
procprivl(CLRPRV, pm_max(P_ALLPRIVS), 0);
}
execvp(cmd, argv);
if (errno == ENOEXEC)
{
register char **p;
char **v;
/*
* assume cmd is a shell script
*/
p = argv;
while (*p++);
if (v = (char**)malloc((p - argv + 1) * sizeof(char**)))
{
p = v;
*p++ = cmd;
if (*argv) argv++;
while (*p++ = *argv++);
execv(getshell(), v);
}
}
_exit(CMDERR);
/*NOTREACHED*/
default:
(void)close(pio[cmdfd]);
cmdproc[proc].fp = fdopen(pio[usrfd], mode);
return(cmdproc[proc].fp);
}
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2018-10-09 22:58 +0200 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <ppj4pc$aoj$1@dont-email.me> |
| In reply to | #136508 |
On 09/10/18 22:50, Scott Lurndal wrote: > David Brown <david.brown@hesbynett.no> writes: >> On 09/10/18 17:23, Kenny McCormack wrote: >>> In article <ppiei3$n9l$1@dont-email.me>, >>> David Brown <david.brown@hesbynett.no> wrote: >>> ... >>>> I don't think the first version is unclear, but I don't see any... >>> >>> Because you're not a moron. You're many things, but a moron you're not. >>> >> >> Why, thank you. >> >>> >>>> is corrected to use "if" rather than "switch"). >>> >>> No. Switch is better. >>> >> >> A switch is better when a switch is appropriate. It won't work here, so >> it is not better. We are branching on a value being less than, equal to >> or greater than zero - a switch won't do that. >> > > $ grep fork */cmd/*/*.c | grep switch These do not match the original code, which tested for pid being less than, equal to or greater than 0. You can't do that with a switch. I am not particularly familiar with the details of fork() - it is not a standard C call, and for all I know it could return a range of negative error values. I still see no advantage of "switch" over "if" for such code - unless it is viewed as such a common idiom that the familiarity is an advantage. However, the point here was not "what is the best way to write a call to fork", but to look at where it might be useful to use the result of an assignment expression, how the code code be re-structured to avoid it, and whether one version is "better" than the other.
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2018-10-09 22:34 +0100 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <U99vD.7170$xE.5145@fx22.am4> |
| In reply to | #136509 |
On 09/10/2018 21:58, David Brown wrote:
> On 09/10/18 22:50, Scott Lurndal wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>>> On 09/10/18 17:23, Kenny McCormack wrote:
>>>> In article <ppiei3$n9l$1@dont-email.me>,
>>>> David Brown <david.brown@hesbynett.no> wrote:
>>>> ...
>>>>> I don't think the first version is unclear, but I don't see any...
>>>>
>>>> Because you're not a moron. You're many things, but a moron you're
>>>> not.
>>>>
>>>
>>> Why, thank you.
>>>
>>>>
>>>>> is corrected to use "if" rather than "switch").
>>>>
>>>> No. Switch is better.
>>>>
>>>
>>> A switch is better when a switch is appropriate. It won't work here, so
>>> it is not better. We are branching on a value being less than, equal to
>>> or greater than zero - a switch won't do that.
>>>
>>
>> $ grep fork */cmd/*/*.c | grep switch
>
> These do not match the original code, which tested for pid being less
> than, equal to or greater than 0. You can't do that with a switch. I
> am not particularly familiar with the details of fork() - it is not a
> standard C call, and for all I know it could return a range of negative
> error values.
>
> I still see no advantage of "switch" over "if" for such code - unless it
> is viewed as such a common idiom that the familiarity is an advantage.
>
>
> However, the point here was not "what is the best way to write a call to
> fork", but to look at where it might be useful to use the result of an
> assignment expression, how the code code be re-structured to avoid it,
> and whether one version is "better" than the other.
This is the original example:
if((pid = fork()) < 0) {
// error handling
} else if(pid == 0) {
// child code
} else {
// parent code
}
The assignment expression is here used so that you can test the result
of a function call twice, without calling the function again which might
cause problems.
But when testing the same integer expression for equality against N
constant possibilities, the switch statement expresses that best. But
the comparisons have to be "==", not "<".
--
bart
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2018-10-10 08:10 +0200 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <ppk54j$loi$1@dont-email.me> |
| In reply to | #136510 |
On 09/10/18 23:34, Bart wrote:
> On 09/10/2018 21:58, David Brown wrote:
>> On 09/10/18 22:50, Scott Lurndal wrote:
>>> David Brown <david.brown@hesbynett.no> writes:
>>>> On 09/10/18 17:23, Kenny McCormack wrote:
>>>>> In article <ppiei3$n9l$1@dont-email.me>,
>>>>> David Brown <david.brown@hesbynett.no> wrote:
>>>>> ...
>>>>>> I don't think the first version is unclear, but I don't see any...
>>>>>
>>>>> Because you're not a moron. You're many things, but a moron you're
>>>>> not.
>>>>>
>>>>
>>>> Why, thank you.
>>>>
>>>>>
>>>>>> is corrected to use "if" rather than "switch").
>>>>>
>>>>> No. Switch is better.
>>>>>
>>>>
>>>> A switch is better when a switch is appropriate. It won't work
>>>> here, so
>>>> it is not better. We are branching on a value being less than,
>>>> equal to
>>>> or greater than zero - a switch won't do that.
>>>>
>>>
>>> $ grep fork */cmd/*/*.c | grep switch
>>
>> These do not match the original code, which tested for pid being less
>> than, equal to or greater than 0. You can't do that with a switch. I
>> am not particularly familiar with the details of fork() - it is not a
>> standard C call, and for all I know it could return a range of
>> negative error values.
>>
>> I still see no advantage of "switch" over "if" for such code - unless
>> it is viewed as such a common idiom that the familiarity is an advantage.
>>
>>
>> However, the point here was not "what is the best way to write a call
>> to fork", but to look at where it might be useful to use the result of
>> an assignment expression, how the code code be re-structured to avoid
>> it, and whether one version is "better" than the other.
>
> This is the original example:
>
> if((pid = fork()) < 0) {
> // error handling
> } else if(pid == 0) {
> // child code
> } else {
> // parent code
> }
>
> The assignment expression is here used so that you can test the result
> of a function call twice, without calling the function again which might
> cause problems.
Writing:
pid = fork();
if (pid < 0) ...
gives you that too. Some people prefer to have the assignment inside
the first "if", others prefer it outside.
>
> But when testing the same integer expression for equality against N
> constant possibilities, the switch statement expresses that best. But
> the comparisons have to be "==", not "<".
>
Yes. And since the original code had " < 0", rather than " == -1", it
could not be turned into a switch.
[toc] | [prev] | [next] | [standalone]
| From | jameskuyper@alumni.caltech.edu |
|---|---|
| Date | 2018-10-09 14:45 -0700 |
| Subject | Re: C idioms (Was: >< swap operator) |
| Message-ID | <aecb78a8-604c-42a2-b307-57fdafda5f9f@googlegroups.com> |
| In reply to | #136509 |
On Tuesday, October 9, 2018 at 4:58:32 PM UTC-4, David Brown wrote: ... > ... I > am not particularly familiar with the details of fork() - it is not a > standard C call, and for all I know it could return a range of negative > error values. From The Open Group Base Specifications Issue 7, 2018 edition IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008): | Upon successful completion, fork() shall return 0 to the child process | and shall return the process ID of the child process to the parent | process. Both processes shall continue to execute from the fork() | function. Otherwise, -1 shall be returned to the parent process, no | child process shall be created, and errno shall be set to indicate the | error. > I still see no advantage of "switch" over "if" for such code - unless it > is viewed as such a common idiom that the familiarity is an advantage. I think it makes the code slightly simpler, I see no reason to object to it. I think anyone daring to modify such code should either know what values fork() can return, or be able to find out quickly.
[toc] | [prev] | [next] | [standalone]
Page 5 of 18 — ← Prev page 1 … 3 4 [5] 6 7 … 18 Next page →
Back to top | Article view | comp.lang.c
csiph-web