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


Groups > comp.lang.c++ > #82003 > unrolled thread

I think references should have been const by default

Started byJuha Nieminen <nospam@thanks.invalid>
First post2021-10-21 05:23 +0000
Last post2021-10-24 14:20 +0000
Articles 20 on this page of 179 — 23 participants

Back to article view | Back to comp.lang.c++


Contents

  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 7 of 9 — ← Prev page 1 2 3 4 5 6 [7] 8 9  Next page →


#82136

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-10-27 04:57 +0000
Message-ID<slam8l$1460$1@gioia.aioe.org>
In reply to#82114
RacingRabbit@watershipdown.co.uk wrote:
>>void func(int (*a)[3]);
> 
> [hopeless effort at self justification]
> 
> You said arrays couldn't be declared as parameters. I showed you they could,
> end of.  What the compiler does with it under the hood is irrelevant.

You seem to be confusing pointers with arrays. Which is not completely
unexpected given that this confusing is very common among less
experienced C (and C++) programmers, as the language makes that
distinction oftentimes hard to discern.

(I know that you will not read past this, but I'm going to try to
explain it anyway.)

An array and a pointer are not the same thing, not even in C. While an
array can often be confused with a pointer, because an array almost always
implicitly converts to a pointer-to-its-fist-element implicitly whenever
one is needed, they are not the same thing. The most prominent situation
where this distinction is made is when using the sizeof operator.
The sizeof of a pointer will be just the size of the pointer itself
(typically 4 or 8). The sizeof of an array will be the entire amount
of bytes that the array takes.

  uint32_t values[10];
  uint32_t *ptr = values;

  sizeof(values); // will be 40.
  sizeof(ptr); // will typically be 4 or 8.

In C, and C++, you cannot pass arrays by value to a function as-is.
You can only pass a pointer to an array. (This pointer will carry
no information about the number of elements in the array, even if
you use the confusing syntax where it looks like it does.)

The only way you can pass an array to a function by value (both
in C and C++) is by enclosing it inside a struct (or class) and
passing an object of that type by value:

  struct MyArray
  {
      int values[10];
  };

  // Genuinely gets the entire array by value, not just a pointer:
  void foo(struct MyArray theArray);

You can use the array syntax in a function parameter declaration, but
that's just confusing syntax sugar:

  // It does not get an array of 10 elements by value, it's just
  // getting a pointer. The "10" in the declaration is meaningless:
  void foo(int values[10])
  {
      printf("%u\n", sizeof(values)); // will print 4 or 8, not 40
  }

Honestly, I think it was a bad idea to add that syntactic sugar to C.
It only causes confusion for no benefit.

[toc] | [prev] | [next] | [standalone]


#82079

FromBart <bc@freeuk.com>
Date2021-10-25 18:19 +0100
Message-ID<sl6ovb$qnp$1@dont-email.me>
In reply to#82077
On 25/10/2021 17:14, RacingRabbit@watershipdown.co.uk wrote:
> On Mon, 25 Oct 2021 10:59:15 -0400
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>> On 10/25/21 10:19 AM, RacingRabbit@watershipdown.co.uk wrote:
>>>> call it with a pointer that's pointing to a string literal. If said
>>>> function does modify the "string" it's getting as parameter, that's UB.
>>>
>>> No idea what UB means, but what'll happen is it'll crash immediately so
>> you'll
>>> soon find out.
>>
>> UB means "Undefined Behavior", a technical term from the C standard
>> which does NOT mean "behavior for which there is no definition". It
>> means "behavior, upon use of a nonportable or erroneous program
>> construct or of erroneous data, for which this document imposes no
>> requirements" (3.4.3). Note that "this document" refers to the C
>> standard; other documents (such as compiler documentation or ABI
>> standards) might define the behavior, without changing the fact that is
>> qualifies as "undefined behavior" as far as the C standard is concerned.
> 
> Any attempt to write to a read only program text area will result in a crash
> regardless of the language.

Data is only put into readonly, write-protected memory when the data 
values are already known before the program starts.

Lots of uses of 'const' are for data not known until the program starts 
execution, and many of these will be reinitialised many times as they 
are declared inside blocks.

Other uses will make take normally mutable data and make it readonly 
when passed to function.

So using write-protected memory is not that much help.

[toc] | [prev] | [next] | [standalone]


#82080

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-10-25 10:48 -0700
Message-ID<87bl3d2dx2.fsf@nosuchdomain.example.com>
In reply to#82077
RacingRabbit@watershipdown.co.uk writes:
> On Mon, 25 Oct 2021 10:59:15 -0400
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>>On 10/25/21 10:19 AM, RacingRabbit@watershipdown.co.uk wrote:
>>>> call it with a pointer that's pointing to a string literal. If said
>>>> function does modify the "string" it's getting as parameter, that's UB.
>>> 
>>> No idea what UB means, but what'll happen is it'll crash immediately so
>>you'll 
>>> soon find out.
>>
>>UB means "Undefined Behavior", a technical term from the C standard
>>which does NOT mean "behavior for which there is no definition". It
>>means "behavior, upon use of a nonportable or erroneous program
>>construct or of erroneous data, for which this document imposes no
>>requirements" (3.4.3). Note that "this document" refers to the C
>>standard; other documents (such as compiler documentation or ABI
>>standards) might define the behavior, without changing the fact that is
>>qualifies as "undefined behavior" as far as the C standard is concerned.
>
> Any attempt to write to a read only program text area will result in a crash
> regardless of the language. It is implicit that its read only in C because
> C also provides the following initialisation which places the string 
> (presumably) on the heap:
>
> char str[] = "hello world";

I suggest that you would benefit more here from asking questions than
from making assertions.

That declaration does not place anything on the heap.  The contents of
str is placed on the stack if it appears within a function definition.
or in the static data area if it appears outside a function definition.

Others have addresses your errors regarding "const".

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#82091

FromRacingRabbit@watershipdown.co.uk
Date2021-10-26 08:21 +0000
Message-ID<sl8dph$pc4$1@gioia.aioe.org>
In reply to#82080
On Mon, 25 Oct 2021 10:48:57 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>RacingRabbit@watershipdown.co.uk writes:
>> Any attempt to write to a read only program text area will result in a crash
>> regardless of the language. It is implicit that its read only in C because
>> C also provides the following initialisation which places the string 
>> (presumably) on the heap:
>>
>> char str[] = "hello world";
>
>I suggest that you would benefit more here from asking questions than
>from making assertions.

I suggest you ease up on being patronising.

>That declaration does not place anything on the heap.  The contents of
>str is placed on the stack if it appears within a function definition.
>or in the static data area if it appears outside a function definition.

Wherever its placed, the point is its modifyable unlike *str = which isn't.

>Others have addresses your errors regarding "const".

Not really. They're just trying to make a case for const being useful in C.
I've yet to see that.

[toc] | [prev] | [next] | [standalone]


#82093

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-10-26 08:37 +0000
Message-ID<sl8enn$14sk$1@gioia.aioe.org>
In reply to#82091
RacingRabbit@watershipdown.co.uk wrote:
> Not really. They're just trying to make a case for const being useful in C.
> I've yet to see that.

It can catch errors where you accidentally try to modify the contents of,
for example, a string literal.

(This doesn't mean that you do like
    char* str = "hello"; str[0] = 'H';
but it does mean that you might do like
    doSomething("hello");
where that doSomething() actually modifies the data behind the pointer
it's given.)

It can also make code more efficient.

What more do you need?

[toc] | [prev] | [next] | [standalone]


#82095

FromRacingRabbit@watershipdown.co.uk
Date2021-10-26 09:02 +0000
Message-ID<sl8g6c$1td8$1@gioia.aioe.org>
In reply to#82093
On Tue, 26 Oct 2021 08:37:13 -0000 (UTC)
Juha Nieminen <nospam@thanks.invalid> wrote:
>RacingRabbit@watershipdown.co.uk wrote:
>> Not really. They're just trying to make a case for const being useful in C.
>> I've yet to see that.
>
>It can catch errors where you accidentally try to modify the contents of,
>for example, a string literal.
>
>(This doesn't mean that you do like
>    char* str = "hello"; str[0] = 'H';
>but it does mean that you might do like
>    doSomething("hello");
>where that doSomething() actually modifies the data behind the pointer
>it's given.)

fenris$ cat t.c
#include <stdio.h>

void func(char *str)
{
	str[0] = 0;
}


int main()
{
	char *str = "hello";
	func(str);
	puts("Worked");
	return 0;
}
fenris$ cc t.c
fenris$ a.out
Bus error: 10
fenris$

[toc] | [prev] | [next] | [standalone]


#82096

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-10-26 11:14 +0000
Message-ID<sl8nvg$1upm$1@gioia.aioe.org>
In reply to#82095
RacingRabbit@watershipdown.co.uk wrote:
> fenris$ a.out
> Bus error: 10

For starters, that's in no way guaranteed to happen. Learn standard C.

Secondly, if you think that a runtime diagnostic is as good as a compile-time
diagnostic, then you have still a LOT to learn about software development.
The earlier in the development process that a bug can be caught, the better.
This is basic software development 101.

The writing-to-a-string-literal might happen only in some cases, not always.
For example, it could depend on the particular contents of some of input
file, or a particular action by the user, a particular command line
parameter, or a myriad of other things that can vary from execution to
execution. In the worst case scenarios the error may happen sporadically
and without a clear pattern, which can make extraordinarily difficult to
debug. Counless hours could be spent in trying to find such an elusive
and obscure bug.

All of which could have been avoided if you just used 'const' and
turned on compiler warnings, and paid attention to them.

There's literally zero reason not to use 'const' for pointers that
are not intended to be used to modify the values they are pointing to.

[toc] | [prev] | [next] | [standalone]


#82101

FromRacingRabbit@watershipdown.co.uk
Date2021-10-26 14:35 +0000
Message-ID<sl93oe$1jdc$1@gioia.aioe.org>
In reply to#82096
On Tue, 26 Oct 2021 11:14:58 -0000 (UTC)
Juha Nieminen <nospam@thanks.invalid> wrote:
>RacingRabbit@watershipdown.co.uk wrote:
>> fenris$ a.out
>> Bus error: 10
>
>For starters, that's in no way guaranteed to happen. Learn standard C.

It is on *nix and thats good enough for me.

>Secondly, if you think that a runtime diagnostic is as good as a compile-time
>diagnostic, then you have still a LOT to learn about software development.

All I'm saying is the bug would exhibit itself pretty quickly.

>All of which could have been avoided if you just used 'const' and
>turned on compiler warnings, and paid attention to them.

I always have warnings on so const not required.

[toc] | [prev] | [next] | [standalone]


#82137

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-10-27 05:01 +0000
Message-ID<slamf0$1460$2@gioia.aioe.org>
In reply to#82101
RacingRabbit@watershipdown.co.uk wrote:
> On Tue, 26 Oct 2021 11:14:58 -0000 (UTC)
> Juha Nieminen <nospam@thanks.invalid> wrote:
>>RacingRabbit@watershipdown.co.uk wrote:
>>> fenris$ a.out
>>> Bus error: 10
>>
>>For starters, that's in no way guaranteed to happen. Learn standard C.
> 
> It is on *nix and thats good enough for me.

I would like a citation to the Single Unix Specification, or to POSIX,
that states so.

(I'm not saying it's not there. I just find it doubtful because not all
CPU architectures have support for that.)

>>Secondly, if you think that a runtime diagnostic is as good as a compile-time
>>diagnostic, then you have still a LOT to learn about software development.
> 
> All I'm saying is the bug would exhibit itself pretty quickly.

Then you are very inexperienced in software development.

[toc] | [prev] | [next] | [standalone]


#82175

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2021-10-29 06:34 -0700
Message-ID<86sfwkdker.fsf@linuxsc.com>
In reply to#82096
Juha Nieminen <nospam@thanks.invalid> writes:

> There's literally zero reason not to use 'const' for pointers that
> are not intended to be used to modify the values they are pointing to.

There is literally zero chance that this statement is not hyperbole.

[toc] | [prev] | [next] | [standalone]


#82105

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2021-10-26 10:43 -0400
Message-ID<sl945t$j8j$2@dont-email.me>
In reply to#82095
On 10/26/21 5:02 AM, RacingRabbit@watershipdown.co.uk wrote:
...
> fenris$ cat t.c
> #include <stdio.h>
> 
> void func(char *str)
> {
> 	str[0] = 0;
> }
> 
> 
> int main()
> {

Try changing the following line:
> 	char *str = "hello";

to
        char greeting[] = "hello";
        char *str = greeting;

> 	func(str);
> 	puts("Worked");
> 	return 0;
> }

You shouldn't get a bus error this time. Do you understand why?

[toc] | [prev] | [next] | [standalone]


#82110

FromRacingRabbit@watershipdown.co.uk
Date2021-10-26 15:21 +0000
Message-ID<sl96e3$11c0$1@gioia.aioe.org>
In reply to#82105
On Tue, 26 Oct 2021 10:43:09 -0400
James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>On 10/26/21 5:02 AM, RacingRabbit@watershipdown.co.uk wrote:
>....
>> fenris$ cat t.c
>> #include <stdio.h>
>> 
>> void func(char *str)
>> {
>> 	str[0] = 0;
>> }
>> 
>> 
>> int main()
>> {
>
>Try changing the following line:
>> 	char *str = "hello";
>
>to
>        char greeting[] = "hello";
>        char *str = greeting;
>
>> 	func(str);
>> 	puts("Worked");
>> 	return 0;
>> }
>
>You shouldn't get a bus error this time. Do you understand why?

Noooo! Really??

Have you actually read anything I wrote or are you just jumping on the
bandwagon of what others have said in order to try and sound clever?

[toc] | [prev] | [next] | [standalone]


#82130

FromDavid Brown <david.brown@hesbynett.no>
Date2021-10-26 22:32 +0200
Message-ID<sl9olc$ig7$1@dont-email.me>
In reply to#82110
On 26/10/2021 17:21, RacingRabbit@watershipdown.co.uk wrote:
> On Tue, 26 Oct 2021 10:43:09 -0400
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:

>> You shouldn't get a bus error this time. Do you understand why?
> 
> Noooo! Really??
> 
> Have you actually read anything I wrote or are you just jumping on the
> bandwagon of what others have said in order to try and sound clever?
> 

Rabbit, I believe you are missing a few key points here.  James is not
trying to /sound/ clever - he /is/ clever.  He is one of the top people
in this group in terms of his knowledge and experience of C and C++, his
accuracy in his explanations, and his patience in helping people.
(There are others here with a similar level of respect and reputation,
whom you have also insulted and disregarded.)

A second key point is that you are wrong about almost everything you
have been writing in this group - so wrong, that you don't even
understand the question.

You'd do well to stop being such an annoying little brat and listen to
the people who are spending time and effort trying to help you
understand the language a little better.

(And yes, I know you'll respond to this with insults - I'm old enough
not to be bothered about what some silly teenager thinks of me.  But I
am also naïve enough to think that not even you are beyond hope.)

[toc] | [prev] | [next] | [standalone]


#82138

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-10-27 05:04 +0000
Message-ID<slamll$1460$3@gioia.aioe.org>
In reply to#82110
RacingRabbit@watershipdown.co.uk wrote:
>>> void func(char *str)
>>
>>Try changing the following line:
>>>      char *str = "hello";
>>
>>to
>>        char greeting[] = "hello";
>>        char *str = greeting;
>>
>>You shouldn't get a bus error this time. Do you understand why?
> 
> Noooo! Really??
> 
> Have you actually read anything I wrote or are you just jumping on the
> bandwagon of what others have said in order to try and sound clever?

Actually he has. He read your assertion that "[] means modifiable
and * means non-modifiable", and is proving you wrong: * can be
perfectly well modifiable.

Of course you will never acknowledge this. Instead you'll just start
dodging with insults.

[toc] | [prev] | [next] | [standalone]


#82104

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2021-10-26 10:42 -0400
Message-ID<sl944g$j8j$1@dont-email.me>
In reply to#82091
On 10/26/21 4:21 AM, RacingRabbit@watershipdown.co.uk wrote:
> On Mon, 25 Oct 2021 10:48:57 -0700
> Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>> RacingRabbit@watershipdown.co.uk writes:
>>> Any attempt to write to a read only program text area will result in a crash
>>> regardless of the language. It is implicit that its read only in C because
>>> C also provides the following initialisation which places the string 
>>> (presumably) on the heap:
>>>
>>> char str[] = "hello world";
>>
>> I suggest that you would benefit more here from asking questions than
>>from making assertions.
> 
> I suggest you ease up on being patronising.

You'll get less patronizing responses when you cease displaying such an
abysmal understanding of C, while believing you understand it better
than others.

>> That declaration does not place anything on the heap.  The contents of
>> str is placed on the stack if it appears within a function definition.
>> or in the static data area if it appears outside a function definition.
> 
> Wherever its placed, the point is its modifyable unlike *str = which isn't.

Your right, but for the wrong reasons. It's true that *str isn't
modifiable, but that's not just because of the "*", it's because str has
been initialized to point at the first character of a string literal. It
could equally easily have been initialized to point at modifiable
memory. Nothing about the str itself makes it read-only.

[toc] | [prev] | [next] | [standalone]


#82106

FromRacingRabbit@watershipdown.co.uk
Date2021-10-26 14:48 +0000
Message-ID<sl94fe$o9$1@gioia.aioe.org>
In reply to#82104
On Tue, 26 Oct 2021 10:42:24 -0400
James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>On 10/26/21 4:21 AM, RacingRabbit@watershipdown.co.uk wrote:
>> On Mon, 25 Oct 2021 10:48:57 -0700
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>>> RacingRabbit@watershipdown.co.uk writes:
>>>> Any attempt to write to a read only program text area will result in a
>crash
>>>> regardless of the language. It is implicit that its read only in C because
>>>> C also provides the following initialisation which places the string 
>>>> (presumably) on the heap:
>>>>
>>>> char str[] = "hello world";
>>>
>>> I suggest that you would benefit more here from asking questions than
>>>from making assertions.
>> 
>> I suggest you ease up on being patronising.
>
>You'll get less patronizing responses when you cease displaying such an
>abysmal understanding of C, while believing you understand it better
>than others.

Says the preening fool.

>Your right, but for the wrong reasons. It's true that *str isn't
>modifiable, but that's not just because of the "*", it's because str has
>been initialized to point at the first character of a string literal. It

So you disagree with what I said then say exactly the same thing yourself.

Ok, well thanks for that. Helpful.

[toc] | [prev] | [next] | [standalone]


#82115

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2021-10-26 11:52 -0400
Message-ID<sl987d$lim$1@dont-email.me>
In reply to#82106
On 10/26/21 10:48 AM, RacingRabbit@watershipdown.co.uk wrote:
> On Tue, 26 Oct 2021 10:42:24 -0400
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
...
>> Your right, but for the wrong reasons. It's true that *str isn't
>> modifiable, but that's not just because of the "*", it's because str has
>> been initialized to point at the first character of a string literal. It
> 
> So you disagree with what I said then say exactly the same thing yourself.

You said that "[] means modifyable, * means read only in every
C implementation I've ever used."

That is false.

What I said corresponds to the following examples:

    char array1[] = "modifiable";
    const char array2[] = "optionally read only";
    char *pointer1 = array1;
    const char *pointer2 = array1;

    array1[0] = 'u'; // permitted
    array2[0] = 'u'; // constraint violation
    *pointer1 = 'u'; // permitted
    *pointer2 = 'u'; // constraint violation

    pointer1 = "optionally read only"; // permitted
    *pointer1  = 'u'; // undefined behavior
    pointer2 = array2;
    *pointer2 = 'u'; // Still a constraint violation.

Despite both of them being declared with [], and therefore according to
you both being modifiable, array1 is modifiable, while array2 may be
placed in read-only memory - but it doesn't have to be.

Despite being declared with *, and therefore according to you being
read-only, pointer1 points at modifiable memory the first time it is
dereferenced, and points at memory that could be read-only the second
time it is dereferenced.
Despite being declared with *, pointer2 differs from pointer 1 in that
it is always a constraint violation to write through it, regardless of
whether or not it points at read-only memory.
Despite being both declared with *, and therefore according to you being
read-only, pointer1 and pointer2 are themselves modifiable, as shown by
the fact that I changed both of their values.

[toc] | [prev] | [next] | [standalone]


#82119

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-10-26 10:22 -0700
Message-ID<87r1c71z10.fsf@nosuchdomain.example.com>
In reply to#82106
RacingRabbit@watershipdown.co.uk writes:
> On Tue, 26 Oct 2021 10:42:24 -0400
> James Kuyper <jameskuyper@alumni.caltech.edu> wrote:
>>On 10/26/21 4:21 AM, RacingRabbit@watershipdown.co.uk wrote:
>>> On Mon, 25 Oct 2021 10:48:57 -0700
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>>>> RacingRabbit@watershipdown.co.uk writes:
>>>>> Any attempt to write to a read only program text area will result in a
>>crash
>>>>> regardless of the language. It is implicit that its read only in C because
>>>>> C also provides the following initialisation which places the string 
>>>>> (presumably) on the heap:
>>>>>
>>>>> char str[] = "hello world";
>>>>
>>>> I suggest that you would benefit more here from asking questions than
>>>>from making assertions.
>>> 
>>> I suggest you ease up on being patronising.
>>
>>You'll get less patronizing responses when you cease displaying such an
>>abysmal understanding of C, while believing you understand it better
>>than others.
>
> Says the preening fool.

James is not a "preening fool".  He's right.

You have joined a forum many of whose participants are experts on the C
programming language.  You have made a number of incorrect statements
about C, and you have shown an inappropriately condescending attitude
while doing so.

This is a great place to learn about C, and I sincerely hope you'll take
advantage of the opportunity.  My advice is to express less certainty
about the statements you make, engage in discussion, and stop insulting
people.

>>Your right, but for the wrong reasons. It's true that *str isn't
>>modifiable, but that's not just because of the "*", it's because str has
>>been initialized to point at the first character of a string literal. It
>
> So you disagree with what I said then say exactly the same thing yourself.

No, that's not what he did.  The array is read-only because it's a
string literal.  You didn't say that.

> Ok, well thanks for that. Helpful.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#82120

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-10-26 10:27 -0700
Message-ID<87mtmv1yu2.fsf@nosuchdomain.example.com>
In reply to#82119
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
> You have joined a forum many of whose participants are experts on the C
> programming language.  You have made a number of incorrect statements
> about C, and you have shown an inappropriately condescending attitude
> while doing so.
>
> This is a great place to learn about C, and I sincerely hope you'll take
> advantage of the opportunity.  My advice is to express less certainty
> about the statements you make, engage in discussion, and stop insulting
> people.

Sorry, I didn't notice which newsgroup I was in.  C++, not C.  (The
rest of what I wrote stands.)

[...]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#82122

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2021-10-26 14:06 -0400
Message-ID<sl9g2r$ipm$1@dont-email.me>
In reply to#82120
On 10/26/21 1:27 PM, Keith Thompson wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> [...]
>> You have joined a forum many of whose participants are experts on the C
>> programming language.  You have made a number of incorrect statements
>> about C, and you have shown an inappropriately condescending attitude
>> while doing so.
>>
>> This is a great place to learn about C, and I sincerely hope you'll take
>> advantage of the opportunity.  My advice is to express less certainty
>> about the statements you make, engage in discussion, and stop insulting
>> people.
> 
> Sorry, I didn't notice which newsgroup I was in.  C++, not C.  (The
> rest of what I wrote stands.)

Even though this is comp.std.c++, and the original message was about
C++, this sub-thread has turned into a discussion about C. However,
everything we're saying about C is true of C++ as well (with some minor
subtle differences), and everything he's saying incorrectly about C is
incorrect for C++, too. The biggest difference in C++ would be that
_Generic() is not supported, but typeinfo() is, which would actually be
a more convenient of proving the truth of what we're saying.

[toc] | [prev] | [next] | [standalone]


Page 7 of 9 — ← Prev page 1 2 3 4 5 6 [7] 8 9  Next page →

Back to top | Article view | comp.lang.c++


csiph-web