Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #82003 > unrolled thread
| Started by | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| First post | 2021-10-21 05:23 +0000 |
| Last post | 2021-10-24 14:20 +0000 |
| Articles | 19 on this page of 179 — 23 participants |
Back to article view | Back to comp.lang.c++
I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-21 05:23 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-21 08:54 +0200
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-21 09:48 +0000
Re: I think references should have been const by default Paavo Helde <myfirstname@osa.pri.ee> - 2021-10-21 12:55 +0300
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-21 12:57 +0200
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-21 13:40 +0000
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-21 15:04 +0100
Re: I think references should have been const by default Manfred <noname@add.invalid> - 2021-10-21 16:41 +0200
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-21 14:57 +0000
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-21 14:51 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-21 12:09 -0400
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-21 23:49 +0100
Re: I think references should have been const by default "james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu> - 2021-10-21 16:21 -0700
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-22 16:14 +0100
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-22 12:04 -0700
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-22 20:47 +0100
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-22 13:29 -0700
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-23 11:54 +0200
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-23 11:22 +0100
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-23 12:35 +0200
Re: I think references should have been const by default Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-23 13:23 +0100
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-23 13:57 +0100
Re: I think references should have been const by default Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-23 21:02 +0100
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-23 15:07 -0700
Re: I think references should have been const by default Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-23 21:15 -0700
Re: I think references should have been const by default Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-23 21:12 -0700
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-22 11:13 +0200
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-22 19:18 -0400
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-22 04:41 +0000
Re: I think references should have been const by default Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-10-23 21:30 +0100
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-25 04:51 +0000
Re: I think references should have been const by default Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-10-26 00:53 +0100
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-22 09:46 +0200
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-22 15:48 +0100
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-23 12:21 +0200
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-23 12:06 +0100
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-23 18:45 +0200
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-23 18:58 +0100
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-24 12:11 +0200
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-24 23:11 +0100
Re: I think references should have been const by default Öö Tiib <ootiib@hot.ee> - 2021-10-24 16:18 -0700
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-25 00:58 +0100
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-25 08:21 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-25 09:47 +0000
Re: I think references should have been const by default Bo Persson <bo@bo-persson.se> - 2021-10-25 12:33 +0200
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-25 14:19 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-25 10:59 -0400
Re: I think references should have been const by default Manfred <noname@add.invalid> - 2021-10-25 17:56 +0200
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-25 11:11 -0700
Re: I think references should have been const by default Manfred <noname@add.invalid> - 2021-10-26 17:15 +0200
Re: I think references should have been const by default Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-29 06:41 -0700
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-25 16:14 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-25 13:14 -0400
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 08:18 +0000
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-26 12:39 +0100
Re: I think references should have been const by default Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-26 14:29 +0100
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-26 15:11 +0100
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-26 09:49 -0700
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-26 18:38 +0100
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-26 11:20 -0700
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-26 20:32 +0100
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-26 22:18 +0200
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-27 04:43 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-27 08:29 +0200
Re: I think references should have been const by default Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-29 06:32 -0700
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-11-01 06:12 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-11-01 08:53 +0100
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-11-01 11:26 -0400
Re: I think references should have been const by default "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-11-02 16:19 +0100
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-11-02 12:54 -0400
Re: I think references should have been const by default Paavo Helde <myfirstname@osa.pri.ee> - 2021-11-02 23:49 +0200
Re: I think references should have been const by default "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-11-03 00:38 +0100
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 14:36 +0000
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-26 15:55 +0100
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 15:26 +0000
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-26 20:35 +0100
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-27 04:44 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 11:27 -0400
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 10:31 -0400
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 14:42 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 11:22 -0400
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 15:30 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 12:23 -0400
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 12:51 -0400
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 14:34 -0400
Re: I think references should have been const by default "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-10-26 12:57 -0700
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-27 07:57 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-27 08:47 +0000
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-27 14:29 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-28 05:17 +0000
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-28 09:30 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-29 04:47 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-29 05:11 +0000
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-29 08:40 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-11-01 06:15 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-27 11:07 +0200
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-27 14:30 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-27 17:30 +0200
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-27 15:46 +0000
Re: I think references should have been const by default scott@slp53.sl.home (Scott Lurndal) - 2021-10-27 16:13 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-27 11:39 -0400
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-27 15:51 +0000
Re: I think references should have been const by default Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-27 17:21 +0100
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-28 09:29 +0000
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-28 11:20 +0100
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-27 12:26 -0400
Re: I think references should have been const by default Anand Hariharan <mailto.anand.hariharan@gmail.com> - 2021-10-31 09:22 -0700
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-11-01 00:13 -0400
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-28 05:20 +0000
Re: I think references should have been const by default "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-10-27 23:10 -0700
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-28 09:30 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-29 04:51 +0000
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-29 08:39 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-11-01 06:34 +0000
Re: I think references should have been const by default Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-10-27 17:41 +0100
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-27 19:02 +0200
Re: I think references should have been const by default Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2021-10-27 18:21 +0100
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-27 11:38 -0400
Re: I think references should have been const by default JohnnyCameLater@whatsthetime.net - 2021-10-27 15:49 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-27 12:36 -0400
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-27 04:57 +0000
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-25 18:19 +0100
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-25 10:48 -0700
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 08:21 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-26 08:37 +0000
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 09:02 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-26 11:14 +0000
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 14:35 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-27 05:01 +0000
Re: I think references should have been const by default Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-29 06:34 -0700
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 10:43 -0400
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 15:21 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-26 22:32 +0200
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-27 05:04 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 10:42 -0400
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 14:48 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 11:52 -0400
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-26 10:22 -0700
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-26 10:27 -0700
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 14:06 -0400
Re: I think references should have been const by default Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-10-29 06:45 -0700
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-29 11:11 -0700
Re: I think references should have been const by default Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-04-25 07:39 -0700
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-04-25 10:59 -0700
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-26 05:29 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-26 08:53 +0200
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-26 08:23 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-26 08:40 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-26 05:18 +0000
Re: I think references should have been const by default David Brown <david.brown@hesbynett.no> - 2021-10-26 09:07 +0200
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-26 11:03 -0400
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-25 10:39 -0400
Re: I think references should have been const by default Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-25 10:56 -0700
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-25 10:30 -0400
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-25 14:39 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-25 11:05 -0400
Re: I think references should have been const by default "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-10-25 12:45 -0700
Re: I think references should have been const by default "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-10-26 11:20 -0700
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-25 05:00 +0000
Re: I think references should have been const by default Bart <bc@freeuk.com> - 2021-10-25 12:13 +0100
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-26 05:36 +0000
Re: I think references should have been const by default Manfred <noname@add.invalid> - 2021-10-25 16:58 +0200
Re: I think references should have been const by default "daniel...@gmail.com" <danielaparker@gmail.com> - 2021-10-22 12:28 -0700
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-21 09:12 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-21 09:52 +0000
Re: I think references should have been const by default RacingRabbit@watershipdown.co.uk - 2021-10-21 10:36 +0000
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-22 04:45 +0000
Re: I think references should have been const by default James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-10-21 12:07 -0400
Re: I think references should have been const by default Paavo Helde <myfirstname@osa.pri.ee> - 2021-10-21 12:18 +0300
Re: I think references should have been const by default Bonita Montero <Bonita.Montero@gmail.com> - 2021-10-21 13:13 +0200
Re: I think references should have been const by default Bo Persson <bo@bo-persson.se> - 2021-10-21 15:08 +0200
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-22 04:45 +0000
Re: I think references should have been const by default Bonita Montero <Bonita.Montero@gmail.com> - 2021-10-22 07:55 +0200
Re: I think references should have been const by default Branimir Maksimovic <branimir.maksimovic@icloud.com> - 2021-10-22 11:21 +0000
Re: I think references should have been const by default "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2021-10-21 13:22 +0200
Re: I think references should have been const by default Juha Nieminen <nospam@thanks.invalid> - 2021-10-22 04:48 +0000
Re: I think references should have been const by default Manfred <noname@add.invalid> - 2021-10-21 13:57 +0200
Re: I think references should have been const by default Branimir Maksimovic <branimir.maksimovic@icloud.com> - 2021-10-21 21:27 +0000
Re: I think references should have been const by default Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-10-24 14:20 +0000
Page 9 of 9 — ← Prev page 1 2 3 4 5 6 7 8 [9]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-10-26 05:36 +0000 |
| Message-ID | <sl844b$132j$1@gioia.aioe.org> |
| In reply to | #82068 |
Bart <bc@freeuk.com> wrote: > I noticed you deftly bypassed the fact that 'const' for 'int' can be > written either side of 'int', or both! That's not really a problem in the right-to-left reading. int const *ptr; can be read as: "ptr is a pointer to a (const int)." and: const int *ptr; can be read as: "ptr is a pointer to an int that's const (ie. a const int)."
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-10-25 16:58 +0200 |
| Message-ID | <sl6glq$bsr$1@gioia.aioe.org> |
| In reply to | #82064 |
On 10/25/2021 7:00 AM, Juha Nieminen wrote: > Bart <bc@freeuk.com> wrote: >> Neither does the syntax make it that obvious which bit of the type is >> refered to, as in: >> >> const int * const * x; > > Actually the syntax *does* make it obvious. You are just reading the type > declaration in the wrong direction. Pointer variable declarations should > be read from right to left (this is a simple but non-obvious trick that > surprisingly few programmers know.) In your example, when we read the > declaration from right to left, it becomes: > > "x is a pointer to a const pointer that points to an int that's const". > > Or, if you want to be a bit clearer: > > "x is a pointer to a (const pointer) that points to an int, the int > itself being const". > > (In other words, x itself is not const and can be modified, but it > points to a const pointer, ie. *x cannot be modified, and this > const pointer is pointing to a const int, ie. **x cannot be modified > either.) > There's still the point that the C standard describes "type qualifiers" both in the context of "declaration-specifiers" and "declarators", and, in the first case, it says that "type specifiers" (e.g. 'int') and "type qualifiers" (like 'const') may appear "in any order". This flexibility is handy in simple declarations, but may be seen as less consistent in case of multiple levels of indirection. In the case of pointer "declarators", on the other hand, "type qualifiers", if any, always occur /after/ their respective '*'. All of this makes sense, after you pay the necessary attention, and it allows to specify the desired qualifiers for each level of indirection, which is a valuable feature. I'd say this is one of the cases where flexibility comes at a price, which, in this case, is worth its value.
[toc] | [prev] | [next] | [standalone]
| From | "daniel...@gmail.com" <danielaparker@gmail.com> |
|---|---|
| Date | 2021-10-22 12:28 -0700 |
| Message-ID | <582f5df2-fff7-43bd-93f7-628595226091n@googlegroups.com> |
| In reply to | #82004 |
On Thursday, October 21, 2021 at 2:54:45 AM UTC-4, David Brown wrote:
> On 21/10/2021 07:23, Juha Nieminen wrote:
> >
> > In other words, I think C++ would have been better if it worked like
> > this:
> >
> > void foo1(std::string& str)
> > {
> > str = "hello"; // error: 'str' is const
> > }
> >
> > void foo2(mutable std::string& str)
> > {
> > str = "hello"; // ok
> > }
It would have been better if std::string was immutable.
> I agree with you entirely. But if we are going for wishful thinking
> about how C++ could have been made better, I'd have preferred "const"
> for all variables and required "mutable" to declare a variable that
> could be modified.
Note though that const does not mean immutable.
Daniel
[toc] | [prev] | [next] | [standalone]
| From | RacingRabbit@watershipdown.co.uk |
|---|---|
| Date | 2021-10-21 09:12 +0000 |
| Message-ID | <skratt$phr$1@gioia.aioe.org> |
| In reply to | #82003 |
On Thu, 21 Oct 2021 05:23:03 -0000 (UTC)
Juha Nieminen <nospam@thanks.invalid> wrote:
>Time and again I see beginner C++ programmers make the same mistake:
>Make functions take objects by non-const reference, even when (in the
>vast, vast majority of cases) the function doesn't modify those objects.
>
>In one particularly egregious case some beginner programmer had written
>a comparator lambda that took two std::string objects by reference,
>wondered why he was getting a compiler error, and then removed the
>references, so it was taking the objects by value. That way it compiled.
>Then he wondered why it was so slow.
>
>I think it was a mistake to make references non-const by default.
>It's logical (and consistent with pointer syntax) of course, but I think
>it was a mistake. In the vast, vast majority of cases if you create a
>reference to something else, you want it to be const (and there are
>many good reasons why it should be const). It's extremely rare to
>explicitly want a non-const reference.
>
>And the thing is, C++98 has a *perfect* keyword to explicitly denote
>that you want a non-const reference, which could have been used for
>this purpose, so no new keyword would be needed for this: 'mutable'.
>
>In other words, I think C++ would have been better if it worked like
>this:
>
> void foo1(std::string& str)
> {
> str = "hello"; // error: 'str' is const
> }
>
> void foo2(mutable std::string& str)
> {
> str = "hello"; // ok
> }
>
>(You could still write "const std::string&", but it would just have
>the exact same meaning as "std::string&", ie. in this case the
>'const' is superfluous, a bit like how 'signed' is superfluous
>in "signed int".)
Looking for logic in C++ keywords is a hiding to nothing. Eg const_cast
actually means remove const'ness , not add it which is frankly bizarre.
You might as well have true mean false and false mean true. Similarly
putting throw() at the end of a function def means it can't throw! Though at
least that insanity has been superceeded by noexcept now.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-10-21 09:52 +0000 |
| Message-ID | <skrd9j$10c$1@gioia.aioe.org> |
| In reply to | #82005 |
RacingRabbit@watershipdown.co.uk wrote: > Looking for logic in C++ keywords is a hiding to nothing. Eg const_cast > actually means remove const'ness , not add it which is frankly bizarre. What would have been a better name for that keyword in your opinion? > Similarly > putting throw() at the end of a function def means it can't throw! Though at > least that insanity has been superceeded by noexcept now. I think it's pretty logical. It just lists all the exceptions that the function can throw. If the list is empty, it means it doesn't throw any exception. If they wanted to be clearer, it should have been "throws(whatever)", but that would have required adding yet another single-use keyword.
[toc] | [prev] | [next] | [standalone]
| From | RacingRabbit@watershipdown.co.uk |
|---|---|
| Date | 2021-10-21 10:36 +0000 |
| Message-ID | <skrfqu$19je$1@gioia.aioe.org> |
| In reply to | #82008 |
On Thu, 21 Oct 2021 09:52:53 -0000 (UTC) Juha Nieminen <nospam@thanks.invalid> wrote: >RacingRabbit@watershipdown.co.uk wrote: >> Looking for logic in C++ keywords is a hiding to nothing. Eg const_cast >> actually means remove const'ness , not add it which is frankly bizarre. > >What would have been a better name for that keyword in your opinion? unconst_cast , noconst_cast, take your pick. > >> Similarly >> putting throw() at the end of a function def means it can't throw! Though at >> least that insanity has been superceeded by noexcept now. > >I think it's pretty logical. It just lists all the exceptions that the >function can throw. If the list is empty, it means it doesn't throw >any exception. Except throw inside a function means throw any exception currently on the stack. You can't have it both ways and for once the C++ committee saw sense and replaced it with noexcept. >If they wanted to be clearer, it should have been "throws(whatever)", but >that would have required adding yet another single-use keyword. There's nothing wrong with single use keywords if they make things clearer. This should have been done with the = 0 in pure virtuals and the spurious int in postfix operator definitions. eg: virtual void myfunc() = 0; -> pure virtual void myfunc(); myclass &operator++(int) -> myclass &operator++() postfix
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-10-22 04:45 +0000 |
| Message-ID | <sktfkf$1i4k$2@gioia.aioe.org> |
| In reply to | #82010 |
RacingRabbit@watershipdown.co.uk wrote:
>>I think it's pretty logical. It just lists all the exceptions that the
>>function can throw. If the list is empty, it means it doesn't throw
>>any exception.
>
> Except throw inside a function means throw any exception currently on the stack.
> You can't have it both ways and for once the C++ committee saw sense and
> replaced it with noexcept.
If 'throw(...)' after a function declaration specifies a list of exceptions
that the function may throw, it's only logical that if this list is empty
then it doesn't throw anything.
You could just as well complain about the multiple different uses of {}.
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2021-10-21 12:07 -0400 |
| Message-ID | <sks386$j2c$1@dont-email.me> |
| In reply to | #82005 |
On 10/21/21 5:12 AM, RacingRabbit@watershipdown.co.uk wrote: ... > Looking for logic in C++ keywords is a hiding to nothing. Eg const_cast > actually means remove const'ness , not add it which is frankly bizarre. You can use const_cast<> to add const as easily as removing it. Doing so is normally unnecessary, because such conversions can be done implicitly, which might be what gave you that impression. You can also add and remove the other qualifier, volatile. Therefore, I think qual_cast<> might have been a better name for it.
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2021-10-21 12:18 +0300 |
| Message-ID | <skrb9f$sfh$1@dont-email.me> |
| In reply to | #82003 |
21.10.2021 08:23 Juha Nieminen kirjutas: > > I think it was a mistake to make references non-const by default. > It's logical (and consistent with pointer syntax) of course, but I think > it was a mistake. Agreed. By default in C is to pass objects by value, so the changes in the object will not affect the caller side. On the caller side the pass by value and pass by reference look the same, so this important feature (no surprises on the caller side) was lost in C++. Using a const reference fixes this loss, so one can even argue that using a const reference, at least by default would also be logical and consistent, in some sense. If it were up to me, I would have required extra syntax on the caller side to pass via non-const reference, like @var. Pushing everything more const would mean the language would behave and feel more "functional" and less "OOP", but that's a good thing.
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2021-10-21 13:13 +0200 |
| Message-ID | <skri1n$4qd$1@dont-email.me> |
| In reply to | #82003 |
You're compulsive.
[toc] | [prev] | [next] | [standalone]
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Date | 2021-10-21 15:08 +0200 |
| Message-ID | <itd73dFsekhU1@mid.individual.net> |
| In reply to | #82012 |
On 2021-10-21 at 13:13, Bonita Montero wrote: > You're compulsive. Who, me?
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-10-22 04:45 +0000 |
| Message-ID | <sktfm2$1i4k$3@gioia.aioe.org> |
| In reply to | #82012 |
Bonita Montero <Bonita.Montero@gmail.com> wrote: > You're compulsive. And you are an asshole.
[toc] | [prev] | [next] | [standalone]
| From | Bonita Montero <Bonita.Montero@gmail.com> |
|---|---|
| Date | 2021-10-22 07:55 +0200 |
| Message-ID | <sktjor$2ut$1@dont-email.me> |
| In reply to | #82030 |
>> You're compulsive. > And you are an asshole. That depends on the situation, but sometimes that's true. I just don't like compulsive personalities that arise problems that don't really exist.
[toc] | [prev] | [next] | [standalone]
| From | Branimir Maksimovic <branimir.maksimovic@icloud.com> |
|---|---|
| Date | 2021-10-22 11:21 +0000 |
| Message-ID | <z8xcJ.4680$Sja8.1553@fx35.iad> |
| In reply to | #82033 |
On 2021-10-22, Bonita Montero <Bonita.Montero@gmail.com> wrote: >>> You're compulsive. > >> And you are an asshole. > > That depends on the situation, but sometimes that's true. > I just don't like compulsive personalities that arise problems > that don't really exist. PEACE&LOVE, brothers and sisters :P -- 7-77-777 Evil Sinner! with software, you repeat same experiment, expecting different results...
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach@gmail.com> |
|---|---|
| Date | 2021-10-21 13:22 +0200 |
| Message-ID | <skrii4$fje$1@dont-email.me> |
| In reply to | #82003 |
On 21 Oct 2021 07:23, Juha Nieminen wrote:
> Time and again I see beginner C++ programmers make the same mistake:
> Make functions take objects by non-const reference, even when (in the
> vast, vast majority of cases) the function doesn't modify those objects.
>
> In one particularly egregious case some beginner programmer had written
> a comparator lambda that took two std::string objects by reference,
> wondered why he was getting a compiler error, and then removed the
> references, so it was taking the objects by value. That way it compiled.
> Then he wondered why it was so slow.
>
> I think it was a mistake to make references non-const by default.
> It's logical (and consistent with pointer syntax) of course, but I think
> it was a mistake. In the vast, vast majority of cases if you create a
> reference to something else, you want it to be const (and there are
> many good reasons why it should be const). It's extremely rare to
> explicitly want a non-const reference.
Agreed. So what can you do about it?
Just define
template< class T > using Ref_ = const T&;
And then write
void foo( Ref_<Baluba> x )
instead of
void foo( const Baluba& x )
A more clever definition in terms of a nested type of a class template,
like the standard library usually does, does not support type deduction
for function templates, but the above supports e.g.
template< class T >
void foo( Ref_<T> x )
with calls like `foo( something )`.
When the same approach is adopted for pointers it supports general
left/west `const`.
The one big drawback of this approach is that code using such
definitions can't be posted to this group without Mr. Fibble complaining
loudly and posting offensive remarks about how it's impossible to grok.
> And the thing is, C++98 has a *perfect* keyword to explicitly denote
> that you want a non-const reference, which could have been used for
> this purpose, so no new keyword would be needed for this: 'mutable'.
>
> In other words, I think C++ would have been better if it worked like
> this:
>
> void foo1(std::string& str)
> {
> str = "hello"; // error: 'str' is const
> }
>
> void foo2(mutable std::string& str)
> {
> str = "hello"; // ok
> }
>
> (You could still write "const std::string&", but it would just have
> the exact same meaning as "std::string&", ie. in this case the
> 'const' is superfluous, a bit like how 'signed' is superfluous
> in "signed int".)
- Alf
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-10-22 04:48 +0000 |
| Message-ID | <sktfqa$1i4k$4@gioia.aioe.org> |
| In reply to | #82013 |
Alf P. Steinbach <alf.p.steinbach@gmail.com> wrote: > Agreed. So what can you do about it? > > Just define > > template< class T > using Ref_ = const T&; > > And then write > > void foo( Ref_<Baluba> x ) > > instead of > > void foo( const Baluba& x ) Doesn't really help with the problem of beginners using non-const references everywhere...
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-10-21 13:57 +0200 |
| Message-ID | <skrkjp$1ku5$1@gioia.aioe.org> |
| In reply to | #82003 |
On 10/21/2021 7:23 AM, Juha Nieminen wrote:
> Time and again I see beginner C++ programmers make the same mistake:
> Make functions take objects by non-const reference, even when (in the
> vast, vast majority of cases) the function doesn't modify those objects.
>
> In one particularly egregious case some beginner programmer had written
> a comparator lambda that took two std::string objects by reference,
> wondered why he was getting a compiler error, and then removed the
> references, so it was taking the objects by value. That way it compiled.
> Then he wondered why it was so slow.
>
> I think it was a mistake to make references non-const by default.
> It's logical (and consistent with pointer syntax) of course, but I think
> it was a mistake. In the vast, vast majority of cases if you create a
> reference to something else, you want it to be const (and there are
> many good reasons why it should be const). It's extremely rare to
> explicitly want a non-const reference.
>
> And the thing is, C++98 has a *perfect* keyword to explicitly denote
> that you want a non-const reference, which could have been used for
> this purpose, so no new keyword would be needed for this: 'mutable'.
>
> In other words, I think C++ would have been better if it worked like
> this:
>
> void foo1(std::string& str)
> {
> str = "hello"; // error: 'str' is const
> }
>
> void foo2(mutable std::string& str)
> {
> str = "hello"; // ok
> }
>
> (You could still write "const std::string&", but it would just have
> the exact same meaning as "std::string&", ie. in this case the
> 'const' is superfluous, a bit like how 'signed' is superfluous
> in "signed int".)
>
Good point. However, I value syntax consistency a lot, so given the
current state of things (non-const default pointers) I think non-const
default references are preferable to me - and I write /many/ more 'const
T&' declarations than 'T&' myself.
In an ideal world, if we were able to have const default pointers as
well, then I would endorse your view entirely.
BTW Alf's alternative has its appeal.
[toc] | [prev] | [next] | [standalone]
| From | Branimir Maksimovic <branimir.maksimovic@icloud.com> |
|---|---|
| Date | 2021-10-21 21:27 +0000 |
| Message-ID | <qXkcJ.27140$mq4.7525@fx46.iad> |
| In reply to | #82003 |
On 2021-10-21, Juha Nieminen <nospam@thanks.invalid> wrote:
> Time and again I see beginner C++ programmers make the same mistake:
> Make functions take objects by non-const reference, even when (in the
> vast, vast majority of cases) the function doesn't modify those objects.
>
> In one particularly egregious case some beginner programmer had written
> a comparator lambda that took two std::string objects by reference,
> wondered why he was getting a compiler error, and then removed the
> references, so it was taking the objects by value. That way it compiled.
> Then he wondered why it was so slow.
>
> I think it was a mistake to make references non-const by default.
> It's logical (and consistent with pointer syntax) of course, but I think
> it was a mistake. In the vast, vast majority of cases if you create a
> reference to something else, you want it to be const (and there are
> many good reasons why it should be const). It's extremely rare to
> explicitly want a non-const reference.
>
> And the thing is, C++98 has a *perfect* keyword to explicitly denote
> that you want a non-const reference, which could have been used for
> this purpose, so no new keyword would be needed for this: 'mutable'.
>
> In other words, I think C++ would have been better if it worked like
> this:
>
> void foo1(std::string& str)
> {
> str = "hello"; // error: 'str' is const
> }
>
> void foo2(mutable std::string& str)
> {
> str = "hello"; // ok
> }
>
> (You could still write "const std::string&", but it would just have
> the exact same meaning as "std::string&", ie. in this case the
> 'const' is superfluous, a bit like how 'signed' is superfluous
> in "signed int".)
Good thinking, but now to late, perhaps with -std=c++22
and latter on?
--
7-77-777
Evil Sinner!
with software, you repeat same experiment, expecting different results...
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2021-10-24 14:20 +0000 |
| Message-ID | <slrnsnaqsk.5o3.grahn+nntp@frailea.sa.invalid> |
| In reply to | #82003 |
On Thu, 2021-10-21, Juha Nieminen wrote:
> Time and again I see beginner C++ programmers make the same mistake:
> Make functions take objects by non-const reference, even when (in the
> vast, vast majority of cases) the function doesn't modify those objects.
I don't often see that mistake. If they do it, surely they must have
learned from really lousy sources, and do other stupid things, too?
It's important and easy for an author or a teacher to describe the
common cases of parameter passing:
void foo(Bar bar);
void foo(const Bar& bar);
And the more exotic ones:
void foo(Bar& bar);
void foo(Bar&& bar);
void foo(Bar* bar);
void foo(const Bar* bar);
void foo(std::unique_ptr<Bar> bar);
// and some I missed I guess
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
[toc] | [prev] | [standalone]
Page 9 of 9 — ← Prev page 1 2 3 4 5 6 7 8 [9]
Back to top | Article view | comp.lang.c++
csiph-web