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


Groups > comp.lang.c > #120068 > unrolled thread

Set the result of void function

Started byThiago Adams <thiago.adams@gmail.com>
First post2017-09-19 14:23 -0700
Last post2017-09-20 15:30 -0700
Articles 20 on this page of 183 — 28 participants

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


Contents

  Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-19 14:23 -0700
    Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-19 14:38 -0700
      Re: Set the result of void function gordonb.tfand@burditt.org (Gordon Burditt) - 2017-09-19 17:16 -0500
      Re: Set the result of void function "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-09-20 00:39 +0200
        Re: Set the result of void function James Kuyper <jameskuyper@verizon.net> - 2017-09-19 22:06 -0400
          Re: Set the result of void function "Pascal J. Bourguignon" <pjb@informatimago.com> - 2017-09-20 06:51 +0200
            Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-20 10:55 +0100
              Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-20 12:11 +0100
              Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 07:17 -0700
            Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-20 11:28 +0100
            Re: Set the result of void function mark.bluemel@gmail.com - 2017-09-20 03:30 -0700
              Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 06:53 -0700
                Re: Set the result of void function Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-09-21 03:50 -0500
                  Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-21 11:00 +0100
                  Re: Set the result of void function scott@slp53.sl.home (Scott Lurndal) - 2017-09-21 12:39 +0000
                    Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-21 14:12 +0100
                      Re: Set the result of void function scott@slp53.sl.home (Scott Lurndal) - 2017-09-21 13:51 +0000
                      Re: Set the result of void function Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-09-21 08:36 -0600
                        Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-21 17:51 +0100
                          Re: Set the result of void function supercat@casperkitty.com - 2017-09-21 10:06 -0700
                            Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-22 08:51 +0200
                              Plunging innocent people into poverty (Was: Set the result of void function) gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-23 09:31 +0000
                                Re: Plunging innocent people into poverty (Was: Set the result of void function) David Brown <david.brown@hesbynett.no> - 2017-09-23 12:09 +0200
                                  Re: Plunging innocent people into poverty (Was: Set the result of void function) gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-23 10:25 +0000
                                Re: Plunging innocent people into poverty Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2017-09-23 10:43 -0600
                                  Re: Plunging innocent people into poverty supercat@casperkitty.com - 2017-09-23 10:41 -0700
                          Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-22 09:37 +0200
                            Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-22 11:27 +0100
                              Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-22 14:42 +0200
                                Re: Set the result of void function Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-09-24 12:09 +0000
                                  Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 08:31 +0200
                                    Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 03:52 -0700
                                      Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 13:25 +0200
                                        Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 04:58 -0700
                                          Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 14:20 +0200
                                        Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 13:44 +0100
                                          Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 15:09 +0200
                                        Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 05:44 -0700
                                          Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 05:58 -0700
                                            Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 15:15 +0200
                                              Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 06:46 -0700
                                                Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-25 16:01 +0200
                                                  Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 07:18 -0700
                                                    Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 07:55 -0700
                                                      Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-25 08:49 -0700
                                                        Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 09:21 -0700
                                                          Re: Set the result of void function supercat@casperkitty.com - 2017-09-25 09:51 -0700
                                                          Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 21:57 +0100
                                                            Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-25 15:03 -0700
                                                              Re: Set the result of void function Öö Tiib <ootiib@hot.ee> - 2017-09-25 21:34 -0700
                                                            Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-26 04:28 -0700
                                                              Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-27 08:26 +0200
                                                                Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-27 11:48 -0400
                                                                  Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 08:54 +0200
                                                                  Re: Set the result of void function gordonb.iddsu@burditt.org (Gordon Burditt) - 2017-09-28 23:33 -0500
                                                                Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 09:15 -0700
                                                                  Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 17:50 +0100
                                                                    Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 10:35 -0700
                                                                    Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-27 18:47 +0100
                                                                      Re: Set the result of void function supercat@casperkitty.com - 2017-09-27 10:52 -0700
                                                                        Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 11:10 -0700
                                                                        Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 09:10 +0200
                                                                    Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 11:06 -0700
                                                                      Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 20:01 +0100
                                                                        Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 12:26 -0700
                                                                          Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 20:38 +0100
                                                                            Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 13:00 -0700
                                                                              Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 21:54 +0100
                                                                                Re: Set the result of void function supercat@casperkitty.com - 2017-09-27 14:12 -0700
                                                                                Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 14:34 -0700
                                                                                  Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-27 23:16 +0100
                                                                                    Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 16:09 -0700
                                                                                      Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 01:12 +0100
                                                                                        Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-28 02:03 +0100
                                                                                          Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-28 17:31 +1300
                                                                                            Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 09:55 +0200
                                                                                              Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-28 21:00 +1300
                                                                                            Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 10:48 +0100
                                                                                              Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 13:20 +0200
                                                                                            Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-28 11:29 +0100
                                                                                        Re: Set the result of void function jameskuyper@verizon.net - 2017-09-27 20:27 -0700
                                                                                      Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:30 +0100
                                                                                        Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-29 19:45 +0100
                                                                                        Re: Set the result of void function Jerry Stuckle <jstucklex@attglobal.net> - 2017-09-29 14:49 -0400
                                                                                Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-27 15:07 -0700
                                                                                Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 09:42 +0200
                                                                                  Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 13:55 +0100
                                                                                    Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 17:22 +0200
                                                                                      Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 09:14 -0700
                                                                                        Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 20:13 +0200
                                                                                          Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:42 +0100
                                                                                      Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-28 09:14 -0700
                                                                                        Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 09:25 -0700
                                                                                        Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 20:17 +0200
                                                                                      Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 17:39 +0100
                                                                                        Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 10:10 -0700
                                                                                          Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 19:05 +0100
                                                                                            Re: Set the result of void function "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2017-09-28 14:20 -0400
                                                                                            Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-29 07:52 +1300
                                                                                            Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 11:59 -0700
                                                                                        Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-28 18:50 +0100
                                                                                          Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 19:47 +0100
                                                                                        Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 21:57 +0200
                                                                                          Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-28 16:14 -0400
                                                                                          Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 13:17 -0700
                                                                                          Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 21:23 +0100
                                                                                            Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 13:55 -0700
                                                                                              Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:50 +0100
                                                                                            Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 13:57 -0700
                                                                                            Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-28 23:18 +0200
                                                                                              Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-28 17:38 -0400
                                                                                                Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 15:54 -0700
                                                                                                Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-29 08:59 +0200
                                                                                              Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 14:43 -0700
                                                                                                Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-29 10:43 +0200
                                                                                                  Re: Set the result of void function supercat@casperkitty.com - 2017-09-29 07:43 -0700
                                                                                              Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-30 19:21 +0100
                                                                                                Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-30 19:45 +0100
                                                                                          Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 13:31 -0700
                                                                                            Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 13:41 -0700
                                                                                              Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 14:07 -0700
                                                                                            Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-28 16:25 -0700
                                                                                              Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 18:45 -0700
                                                                                                Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-28 19:54 -0700
                                                                                                  Re: Set the result of void function jameskuyper@verizon.net - 2017-09-28 20:51 -0700
                                                                                                    Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-28 22:39 -0700
                                                                                                      Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 09:16 -0700
                                                                                                        Re: Set the result of void function gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-29 16:17 +0000
                                                                                                        Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 11:05 -0700
                                                                                                          Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 11:23 -0700
                                                                                                            Re: Set the result of void function supercat@casperkitty.com - 2017-09-29 12:15 -0700
                                                                                                            Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:04 -0700
                                                                                                              Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 16:44 -0700
                                                                                                                Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-30 10:04 -0700
                                                                                                                  Re: Set the result of void function supercat@casperkitty.com - 2017-09-30 10:33 -0700
                                                                                                          Re: Set the result of void function jameskuyper@verizon.net - 2017-09-29 11:26 -0700
                                                                                                            Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:03 -0700
                                                                                                      Re: Set the result of void function jameskuyper@verizon.net - 2017-09-29 09:44 -0700
                                                                                                        Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 11:15 -0700
                                                                                                          Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 11:35 -0700
                                                                                                            Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:11 -0700
                                                                                                            Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-29 16:14 -0700
                                                                                                              Re: Set the result of void function supercat@casperkitty.com - 2017-09-30 08:55 -0700
                                                                                                          Re: Set the result of void function jameskuyper@verizon.net - 2017-09-29 11:36 -0700
                                                                                                    Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-29 12:05 +0100
                                                                                                  Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-29 12:17 +0100
                                                                                                  Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-29 09:15 -0700
                                                                                        Re: Set the result of void function Ian Collins <ian-news@hotmail.com> - 2017-09-29 09:42 +1300
                                                                                          Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-28 21:55 +0100
                                                                                            Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 14:12 -0700
                                                                                              Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-28 17:22 -0400
                                                                                              Re: Set the result of void function Gareth Owen <gwowen@gmail.com> - 2017-09-29 19:50 +0100
                                                                                    Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 09:00 -0700
                                                                                      Re: Set the result of void function supercat@casperkitty.com - 2017-09-28 09:35 -0700
                                                                                        Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-28 10:57 -0700
                                                        Re: Set the result of void function Thiago Adams <thiago.adams@gmail.com> - 2017-09-25 10:35 -0700
                                            Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 06:57 -0700
                                      Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 16:32 +0100
                                        Re: Set the result of void function Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-25 08:43 -0700
                                          Re: Set the result of void function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-25 22:12 +0100
                                        Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-25 09:03 -0700
                                    Re: Set the result of void function Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-09-25 14:17 +0000
            Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-20 11:32 -0400
          Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 01:50 -0700
            Re: Set the result of void function David Kleinecke <dkleinecke@gmail.com> - 2017-09-20 15:56 -0700
    Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-19 23:01 +0100
      Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-20 15:40 +0200
        Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-20 08:50 -0700
          Re: Set the result of void function David Brown <david.brown@hesbynett.no> - 2017-09-20 22:52 +0200
            Re: Set the result of void function supercat@casperkitty.com - 2017-09-20 15:04 -0700
      Re: Set the result of void function supercat@casperkitty.com - 2017-09-20 07:39 -0700
    Re: Set the result of void function jameskuyper@verizon.net - 2017-09-19 15:18 -0700
      Re: Set the result of void function bartc <bc@freeuk.com> - 2017-09-20 01:21 +0100
        Re: Set the result of void function jameskuyper@verizon.net - 2017-09-19 19:40 -0700
    Re: Set the result of void function rockbrentwood@gmail.com - 2017-09-19 16:36 -0700
      Re: Set the result of void function James Kuyper <jameskuyper@verizon.net> - 2017-09-19 22:13 -0400
      Re: Set the result of void function gazelle@shell.xmission.com (Kenny McCormack) - 2017-09-22 01:48 +0000
    Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-19 19:36 -0700
    Re: Set the result of void function mark.bluemel@gmail.com - 2017-09-20 01:00 -0700
      Re: Set the result of void function fir <profesor.fir@gmail.com> - 2017-09-20 02:01 -0700
    Re: Set the result of void function Keith Thompson <kst-u@mib.org> - 2017-09-20 08:36 -0700
    Re: Set the result of void function "James R. Kuyper" <jameskuyper@verizon.net> - 2017-09-20 11:36 -0400
    Re: Set the result of void function John Bode <jfbode1029@gmail.com> - 2017-09-20 15:30 -0700

Page 3 of 10 — ← Prev page 1 2 [3] 4 5 … 10  Next page →


#120289

FromThiago Adams <thiago.adams@gmail.com>
Date2017-09-25 06:46 -0700
Message-ID<8c29ee78-bc72-41b4-8c06-880f15ebd63e@googlegroups.com>
In reply to#120287
On Monday, September 25, 2017 at 10:15:59 AM UTC-3, David Brown wrote:
> On 25/09/17 14:58, Thiago Adams wrote:
> > On Monday, September 25, 2017 at 9:45:07 AM UTC-3, Thiago Adams wrote:
> > 
> > [...]
> > 
> >> This is how I write swap in C.
> >>
> >> void X_Swap(struct X* a, struct X* b)
> >> {
> >>   struct X tmp = *a;
> >>   *a = *b; 
> >>   *b = tmp;
> >> }
> >>
> >> I don't see any problem in write swap once. The problem is to write 
> >> the same code many times. But this is not the worst case
> >> because, at least, the code doesn't change when I change the 
> >> type X.
> >>
> >> Constructors/destructors are sensible when we change the types, then 
> >> they require more maintenance.
> >>
> >> My C code generator can generate swap from C code, I just need to 
> >> put this 'function-instantiation-declaration' line. 
> > 
> > Comparing C++ swap with C, the key point is to ask if C want's
> > function overloading / templates / operator overloading.
> > 
> > If you open the door for one of these features you can change the 
> > language radically.
> 
> I believe Jacob has operator overloading in his C compiler, without
> changing the language too radically.
> 
> And gcc extensions let you write:
> 
> #define swap(a, b) \
> 	do { \
> 		typeof(a) t = a; \
> 		a = b; \
> 		b = t; \
> 	} while (0)
> 
> 
> 
> > 
> > I tried to keep C as it is with my generator. Then I need manually
> > instantiate the function, differently from C++ templates that generates
> > the instantiation when it's necessary. I think the way C works is 
> > interesting for review critical systems. 
> > In C, each action (apart of basic ones like copy and operators +-*  etc) 
> > has a unique name and concept is build around function call.
> >

In some cases the swap operation is not just a copy. Let's say
you have a pointer for something inside your struct.
Then we need override swap.

One way we could have this in a imaginary extension, or code generator
is like this:

void X_Swap(struct X* p) operator swap
{

}

X x1;
X x2;

//selects the correct functions
//overloading
swap(&x1, &x2); 

And if you use this type inside Y;

struct Y
{
  struct X x;
}

you also needs to customize Y swap or to have generators for swap.
The same already happens for constructor/destructor operator >  < .

If we had swap as a build-in operator it could work just for simple
types like operator plus to avoid making it a more complex and general concept.
First, the typeof could be standardized.

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


#120291

FromDavid Brown <david.brown@hesbynett.no>
Date2017-09-25 16:01 +0200
Message-ID<oqb28b$eek$1@dont-email.me>
In reply to#120289
On 25/09/17 15:46, Thiago Adams wrote:
> On Monday, September 25, 2017 at 10:15:59 AM UTC-3, David Brown wrote:
>> On 25/09/17 14:58, Thiago Adams wrote:
>>> On Monday, September 25, 2017 at 9:45:07 AM UTC-3, Thiago Adams wrote:
>>>
>>> [...]
>>>
>>>> This is how I write swap in C.
>>>>
>>>> void X_Swap(struct X* a, struct X* b)
>>>> {
>>>>   struct X tmp = *a;
>>>>   *a = *b; 
>>>>   *b = tmp;
>>>> }
>>>>
>>>> I don't see any problem in write swap once. The problem is to write 
>>>> the same code many times. But this is not the worst case
>>>> because, at least, the code doesn't change when I change the 
>>>> type X.
>>>>
>>>> Constructors/destructors are sensible when we change the types, then 
>>>> they require more maintenance.
>>>>
>>>> My C code generator can generate swap from C code, I just need to 
>>>> put this 'function-instantiation-declaration' line. 
>>>
>>> Comparing C++ swap with C, the key point is to ask if C want's
>>> function overloading / templates / operator overloading.
>>>
>>> If you open the door for one of these features you can change the 
>>> language radically.
>>
>> I believe Jacob has operator overloading in his C compiler, without
>> changing the language too radically.
>>
>> And gcc extensions let you write:
>>
>> #define swap(a, b) \
>> 	do { \
>> 		typeof(a) t = a; \
>> 		a = b; \
>> 		b = t; \
>> 	} while (0)
>>
>>
>>
>>>
>>> I tried to keep C as it is with my generator. Then I need manually
>>> instantiate the function, differently from C++ templates that generates
>>> the instantiation when it's necessary. I think the way C works is 
>>> interesting for review critical systems. 
>>> In C, each action (apart of basic ones like copy and operators +-*  etc) 
>>> has a unique name and concept is build around function call.
>>>
> 
> In some cases the swap operation is not just a copy. Let's say
> you have a pointer for something inside your struct.
> Then we need override swap.

Yes indeed.  That is one of the key reasons you can have a good "swap"
in C++, but not in C.  In C, you can't override functions - so you need
a new name (like X_Swap) for each different version.  You can use
_Generic to tie them together.

> 
> One way we could have this in a imaginary extension, or code generator
> is like this:
> 
> void X_Swap(struct X* p) operator swap
> {
> 
> }
> 
> X x1;
> X x2;
> 
> //selects the correct functions
> //overloading
> swap(&x1, &x2); 
> 
> And if you use this type inside Y;
> 
> struct Y
> {
>   struct X x;
> }
> 
> you also needs to customize Y swap or to have generators for swap.
> The same already happens for constructor/destructor operator >  < .
> 
> If we had swap as a build-in operator it could work just for simple
> types like operator plus to avoid making it a more complex and general concept.
> First, the typeof could be standardized.
> 

"typeof" could, I think, be standardised - but as you note, adding
overloading, templates, etc., would change the language dramatically.  I
don't know whether there is a place for a "C+" language that has some
features like that, but is not C++.  I suspect that you would lose the
benefits of C (the clarity, simplicity, and stability of the language)
while also missing many of the useful features of C++, as well as
lacking good implementations.

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


#120294

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2017-09-25 07:18 -0700
Message-ID<001b7bdd-f28a-4747-80da-81404481b320@googlegroups.com>
In reply to#120291
On Monday, September 25, 2017 at 3:02:05 PM UTC+1, David Brown wrote:
> On 25/09/17 15:46, Thiago Adams wrote:
> >
> > In some cases the swap operation is not just a copy. Let's say
> > you have a pointer for something inside your struct.
> > Then we need override swap.
> 
> Yes indeed.  That is one of the key reasons you can have a good "swap"
> in C++, but not in C.  In C, you can't override functions - so you need
> a new name (like X_Swap) for each different version.  You can use
> _Generic to tie them together.
> 
swapping is like copying. But you have to think in the C way. To operate
on memory rather than whatever that memory represents.

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


#120298

FromThiago Adams <thiago.adams@gmail.com>
Date2017-09-25 07:55 -0700
Message-ID<74b5ddce-96ec-48aa-a16c-a5a4207c17fe@googlegroups.com>
In reply to#120294
On Monday, September 25, 2017 at 11:19:08 AM UTC-3, Malcolm McLean wrote:
> On Monday, September 25, 2017 at 3:02:05 PM UTC+1, David Brown wrote:
> > On 25/09/17 15:46, Thiago Adams wrote:
> > >
> > > In some cases the swap operation is not just a copy. Let's say
> > > you have a pointer for something inside your struct.
> > > Then we need override swap.
> > 
> > Yes indeed.  That is one of the key reasons you can have a good "swap"
> > in C++, but not in C.  In C, you can't override functions - so you need
> > a new name (like X_Swap) for each different version.  You can use
> > _Generic to tie them together.
> > 
> swapping is like copying. But you have to think in the C way. To operate
> on memory rather than whatever that memory represents.

What I am saying is that swap is not always a copy.
If you create a string object with an small buffer, then you have a pointer
that can point to your buffer inside the string or to external memory heap.
then to swap string object you cannot copy. you need to fix the pointer.

typedef struct 
{
   char *p;
   char buffer[10];
} String ;

void String_Init(String* p) {
  p->p = p->buffer;
}

if you need more than 10 chars you can allocate on heap.

to swap this string you need to fix the internal pointer.

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


#120306

FromKeith Thompson <kst-u@mib.org>
Date2017-09-25 08:49 -0700
Message-ID<lnmv5i22z2.fsf@kst-u.example.com>
In reply to#120298
Thiago Adams <thiago.adams@gmail.com> writes:
[...]
> What I am saying is that swap is not always a copy.
> If you create a string object with an small buffer, then you have a pointer
> that can point to your buffer inside the string or to external memory heap.
> then to swap string object you cannot copy. you need to fix the pointer.
>
> typedef struct 
> {
>    char *p;
>    char buffer[10];
> } String ;
>
> void String_Init(String* p) {
>   p->p = p->buffer;
> }
>
> if you need more than 10 chars you can allocate on heap.
>
> to swap this string you need to fix the internal pointer.

IF you're working with data structures like that, perhaps it would be
better to rework your code so you can swap pointers rather than full
objects.

More generally, swapping is such a simple operation that you don't
really gain all that much from making it generic.  If you're using a
language that lets you do so easily, that's fine, but in C I typically
just write the code inline:

    {
        const int old_x = x;
        x = y;
        y = old_x;
    }

It's a little more complicated than
    (x, y) = (y, x);
or
    std::swap(x, y);
but it's not *that* bad.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


#120311

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2017-09-25 09:21 -0700
Message-ID<9546ff45-2666-4f32-8905-8d4baba8a74d@googlegroups.com>
In reply to#120306
On Monday, September 25, 2017 at 4:49:18 PM UTC+1, Keith Thompson wrote:
> Thiago Adams <thiago.adams@gmail.com> writes:
> 
> More generally, swapping is such a simple operation that you don't
> really gain all that much from making it generic.  If you're using a
> language that lets you do so easily, that's fine, but in C I typically
> just write the code inline:
> 
>     {
>         const int old_x = x;
>         x = y;
>         y = old_x;
>     }
> 
> It's a little more complicated than
>     (x, y) = (y, x);
> or
>     std::swap(x, y);
> but it's not *that* bad.
> 
The problem comes when C or whatever language you are using doesn't
allow the temporary variable approach

double v1[3], v2[3];
double temp[3] = v1;
v1 = v2;
v2 = temp;

no good. You can do it memberwise, of course. But then it's no longer a simple
trivial few lines of code.
 

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


#120314

Fromsupercat@casperkitty.com
Date2017-09-25 09:51 -0700
Message-ID<5d16310f-e32b-4f39-a26b-ba5c6ffb4a28@googlegroups.com>
In reply to#120311
On Monday, September 25, 2017 at 11:22:15 AM UTC-5, Malcolm McLean wrote:
> The problem comes when C or whatever language you are using doesn't
> allow the temporary variable approach
> 
> double v1[3], v2[3];
> double temp[3] = v1;
> v1 = v2;
> v2 = temp;
> 
> no good. You can do it memberwise, of course. But then it's no longer a simple
> trivial few lines of code.

Standardizing a "typeof" operator would make it possible for code to
handle swaps of arbitrary non-array objects in a statement macro, while
adding some type checking to boot.  For array objects, it might be simpler
to have a syntax to specify a array type which could be passed as a function
argument and could accept assignments from arrays of the proper element type
and size.  If e.g. the syntax "int[16 struct]" were used to indicate such a
16-element array of "int", then code which wanted to copy 16 elements from
an int* to such an array could use:

    myArray = *(int[16 struct]*)theIntPtr;

If applying typeof to an int[16] would yield an int[16 struct], then an
exchange macro could be made to operate on lvalues of any type.

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


#120330

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-09-25 21:57 +0100
Message-ID<877ewm1ook.fsf@bsb.me.uk>
In reply to#120311
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:

> On Monday, September 25, 2017 at 4:49:18 PM UTC+1, Keith Thompson wrote:
>> Thiago Adams <thiago.adams@gmail.com> writes:
>> 
>> More generally, swapping is such a simple operation that you don't
>> really gain all that much from making it generic.  If you're using a
>> language that lets you do so easily, that's fine, but in C I typically
>> just write the code inline:
>> 
>>     {
>>         const int old_x = x;
>>         x = y;
>>         y = old_x;
>>     }
>> 
>> It's a little more complicated than
>>     (x, y) = (y, x);
>> or
>>     std::swap(x, y);
>> but it's not *that* bad.
>> 
> The problem comes when C or whatever language you are using doesn't
> allow the temporary variable approach
>
> double v1[3], v2[3];
> double temp[3] = v1;
> v1 = v2;
> v2 = temp;
>
> no good. You can do it memberwise, of course. But then it's no longer a simple
> trivial few lines of code.

Sure, but it's only one more line:

     double v1[3], v2[3];
     double temp[3];
     memcpy(temp, v1, sizeof v1);
     memcpy(v1,   v2, sizeof v1);
     memcpy(v2, temp, sizeof v1);

The memcpy makes them less simple, and the loss of type-checking makes
then less trivial, but they are still few!

-- 
Ben.

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


#120335

FromKeith Thompson <kst-u@mib.org>
Date2017-09-25 15:03 -0700
Message-ID<lna81i1lng.fsf@kst-u.example.com>
In reply to#120330
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>> On Monday, September 25, 2017 at 4:49:18 PM UTC+1, Keith Thompson wrote:
>>> Thiago Adams <thiago.adams@gmail.com> writes:
>>> More generally, swapping is such a simple operation that you don't
>>> really gain all that much from making it generic.  If you're using a
>>> language that lets you do so easily, that's fine, but in C I typically
>>> just write the code inline:
>>> 
>>>     {
>>>         const int old_x = x;
>>>         x = y;
>>>         y = old_x;
>>>     }
>>> 
>>> It's a little more complicated than
>>>     (x, y) = (y, x);
>>> or
>>>     std::swap(x, y);
>>> but it's not *that* bad.
>>> 
>> The problem comes when C or whatever language you are using doesn't
>> allow the temporary variable approach
>>
>> double v1[3], v2[3];
>> double temp[3] = v1;
>> v1 = v2;
>> v2 = temp;
>>
>> no good. You can do it memberwise, of course. But then it's no longer
>> a simple trivial few lines of code.
>
> Sure, but it's only one more line:
>
>      double v1[3], v2[3];
>      double temp[3];
>      memcpy(temp, v1, sizeof v1);
>      memcpy(v1,   v2, sizeof v1);
>      memcpy(v2, temp, sizeof v1);
>
> The memcpy makes them less simple, and the loss of type-checking makes
> then less trivial, but they are still few!

I know it's conventional to call the temporary object "temp" (or
"tmp", or "t"), but I find that I can easily mess up the order of
the assignments if I'm not very careful.  I think it's the imposed
asymmetry that throws me off, with one value copied indirectly via
a temporary and the other copied directly.  That's why I use a name
like "old_x", as in my code sample above.  In case it gets snipped:

    {
        const int old_x = x;
        x = y;
        y = old_x;
    }

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


#120339

FromÖö Tiib <ootiib@hot.ee>
Date2017-09-25 21:34 -0700
Message-ID<afa3b723-9b1c-4208-9ea1-5ea55eb1a7f8@googlegroups.com>
In reply to#120335
On Tuesday, 26 September 2017 01:03:34 UTC+3, Keith Thompson  wrote:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> > Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> >> On Monday, September 25, 2017 at 4:49:18 PM UTC+1, Keith Thompson wrote:
> >>> Thiago Adams <thiago.adams@gmail.com> writes:
> >>> More generally, swapping is such a simple operation that you don't
> >>> really gain all that much from making it generic.  If you're using a
> >>> language that lets you do so easily, that's fine, but in C I typically
> >>> just write the code inline:
> >>> 
> >>>     {
> >>>         const int old_x = x;
> >>>         x = y;
> >>>         y = old_x;
> >>>     }
> >>> 
> >>> It's a little more complicated than
> >>>     (x, y) = (y, x);
> >>> or
> >>>     std::swap(x, y);
> >>> but it's not *that* bad.
> >>> 
> >> The problem comes when C or whatever language you are using doesn't
> >> allow the temporary variable approach
> >>
> >> double v1[3], v2[3];
> >> double temp[3] = v1;
> >> v1 = v2;
> >> v2 = temp;
> >>
> >> no good. You can do it memberwise, of course. But then it's no longer
> >> a simple trivial few lines of code.
> >
> > Sure, but it's only one more line:
> >
> >      double v1[3], v2[3];
> >      double temp[3];
> >      memcpy(temp, v1, sizeof v1);
> >      memcpy(v1,   v2, sizeof v1);
> >      memcpy(v2, temp, sizeof v1);
> >
> > The memcpy makes them less simple, and the loss of type-checking makes
> > then less trivial, but they are still few!
> 
> I know it's conventional to call the temporary object "temp" (or
> "tmp", or "t"), but I find that I can easily mess up the order of
> the assignments if I'm not very careful.  I think it's the imposed
> asymmetry that throws me off, with one value copied indirectly via
> a temporary and the other copied directly.  That's why I use a name
> like "old_x", as in my code sample above.  In case it gets snipped:
> 
>     {
>         const int old_x = x;
>         x = y;
>         y = old_x;
>     }

Yes but it is still quoted above so why not to make example about
arrays (to where the discussion evolved) like:

      double v1[3], v2[3];
      // ...
      double old_v1[3];
      memcpy(old_v1, v1, sizeof v1);
      memcpy(v1,   v2, sizeof v1);
      memcpy(v2, old_v1, sizeof v1);

 

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


#120342

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2017-09-26 04:28 -0700
Message-ID<65ac971c-10a1-41b1-876d-cdded04ea432@googlegroups.com>
In reply to#120330
On Monday, September 25, 2017 at 9:57:54 PM UTC+1, Ben Bacarisse wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> 
> > On Monday, September 25, 2017 at 4:49:18 PM UTC+1, Keith Thompson wrote:
> >> Thiago Adams <thiago.adams@gmail.com> writes:
> >> 
> >> More generally, swapping is such a simple operation that you don't
> >> really gain all that much from making it generic.  If you're using a
> >> language that lets you do so easily, that's fine, but in C I typically
> >> just write the code inline:
> >> 
> >>     {
> >>         const int old_x = x;
> >>         x = y;
> >>         y = old_x;
> >>     }
> >> 
> >> It's a little more complicated than
> >>     (x, y) = (y, x);
> >> or
> >>     std::swap(x, y);
> >> but it's not *that* bad.
> >> 
> > The problem comes when C or whatever language you are using doesn't
> > allow the temporary variable approach
> >
> > double v1[3], v2[3];
> > double temp[3] = v1;
> > v1 = v2;
> > v2 = temp;
> >
> > no good. You can do it memberwise, of course. But then it's no longer a simple
> > trivial few lines of code.
> 
> Sure, but it's only one more line:
> 
>      double v1[3], v2[3];
>      double temp[3];
>      memcpy(temp, v1, sizeof v1);
>      memcpy(v1,   v2, sizeof v1);
>      memcpy(v2, temp, sizeof v1);
> 
> The memcpy makes them less simple, and the loss of type-checking makes
> then less trivial, but they are still few!
> 
But you're using a subroutine call. So you might as well use memswap(). Except
memswap() isn't standard, though it should be - I think the reason is that it should
also be the accepted, most efficient way of swapping two variables, and that
requires a compiler patch to many compilers.

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


#120356

FromDavid Brown <david.brown@hesbynett.no>
Date2017-09-27 08:26 +0200
Message-ID<oqfgaq$b8q$1@dont-email.me>
In reply to#120342
On 26/09/17 13:28, Malcolm McLean wrote:
> On Monday, September 25, 2017 at 9:57:54 PM UTC+1, Ben Bacarisse wrote:
>> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>
>>> On Monday, September 25, 2017 at 4:49:18 PM UTC+1, Keith Thompson wrote:
>>>> Thiago Adams <thiago.adams@gmail.com> writes:
>>>>
>>>> More generally, swapping is such a simple operation that you don't
>>>> really gain all that much from making it generic.  If you're using a
>>>> language that lets you do so easily, that's fine, but in C I typically
>>>> just write the code inline:
>>>>
>>>>     {
>>>>         const int old_x = x;
>>>>         x = y;
>>>>         y = old_x;
>>>>     }
>>>>
>>>> It's a little more complicated than
>>>>     (x, y) = (y, x);
>>>> or
>>>>     std::swap(x, y);
>>>> but it's not *that* bad.
>>>>
>>> The problem comes when C or whatever language you are using doesn't
>>> allow the temporary variable approach
>>>
>>> double v1[3], v2[3];
>>> double temp[3] = v1;
>>> v1 = v2;
>>> v2 = temp;
>>>
>>> no good. You can do it memberwise, of course. But then it's no longer a simple
>>> trivial few lines of code.
>>
>> Sure, but it's only one more line:
>>
>>      double v1[3], v2[3];
>>      double temp[3];
>>      memcpy(temp, v1, sizeof v1);
>>      memcpy(v1,   v2, sizeof v1);
>>      memcpy(v2, temp, sizeof v1);
>>
>> The memcpy makes them less simple, and the loss of type-checking makes
>> then less trivial, but they are still few!
>>
> But you're using a subroutine call. 

C does not have subroutines.  I think you mean a function call?

And since memcpy is a standard function, compilers will often optimise
them.  A quick test with gcc on this:

double v1[3];
double v2[3];

void swap_vs(void) {
    double temp[3];
    memcpy(temp, v1, sizeof v1);
    memcpy(v1, v2, sizeof v1);
    memcpy(v2, temp, sizeof v1);
}

shows that the compiler not only does not make any function calls, it
does not make a temporary array either - the moves are intermixed for
greater efficiency.

> So you might as well use memswap(). Except
> memswap() isn't standard, though it should be - I think the reason is that it should
> also be the accepted, most efficient way of swapping two variables, and that
> requires a compiler patch to many compilers.
> 

We have already seen why there could not be a standard "swap" function
in C - or at least, why such a function could not be made efficiently,
nor convenient to use.  You /could/ make a "memswap" function - but why
bother?  It is not often needed, easy to write swaps by hand for simple
cases, and for complex swap cases you would want a specialised function
anyway.

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


#120372

From"James R. Kuyper" <jameskuyper@verizon.net>
Date2017-09-27 11:48 -0400
Message-ID<f245db6e-1a08-0fe2-9afa-824fa966fe26@verizon.net>
In reply to#120356
On 2017-09-27 02:26, David Brown wrote:
...
> C does not have subroutines.  I think you mean a function call?

Does <https://en.wikipedia.org/wiki/Subroutine> need modification? It 
says: "In computer programming, a subroutine is a sequence of program 
instructions that perform a specific task, packaged as a unit. This unit 
can then be used in programs wherever that particular task should be 
performed."
"In different programming languages, a subroutine may be called ... a 
function ..."
"In the C and C++ programming languages, subprograms are termed functions.".

How does your definition for the term "subroutine" differ from that one, 
in a way that allows you to exclude C functions?

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


#120426

FromDavid Brown <david.brown@hesbynett.no>
Date2017-09-28 08:54 +0200
Message-ID<oqi6av$33j$1@dont-email.me>
In reply to#120372
On 27/09/17 17:48, James R. Kuyper wrote:
> On 2017-09-27 02:26, David Brown wrote:
> ...
>> C does not have subroutines.  I think you mean a function call?
> 
> Does <https://en.wikipedia.org/wiki/Subroutine> need modification? It
> says: "In computer programming, a subroutine is a sequence of program
> instructions that perform a specific task, packaged as a unit. This unit
> can then be used in programs wherever that particular task should be
> performed."
> "In different programming languages, a subroutine may be called ... a
> function ..."
> "In the C and C++ programming languages, subprograms are termed
> functions.".
> 
> How does your definition for the term "subroutine" differ from that one,
> in a way that allows you to exclude C functions?

I apologise for my pedantry on C terms here - especially as it seems to
have lead to a people missing the main point of my post (that calling a
function like memcpy() does not necessarily mean non-optimal code or
function calls at the object code level).

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


#120523

Fromgordonb.iddsu@burditt.org (Gordon Burditt)
Date2017-09-28 23:33 -0500
Message-ID<efGdne_2Y76IUFDEnZ2dnUU7-XnNnZ2d@posted.internetamerica>
In reply to#120372
>> C does not have subroutines.  I think you mean a function call?
> 
> Does <https://en.wikipedia.org/wiki/Subroutine> need modification? It 
> says: "In computer programming, a subroutine is a sequence of program 
> instructions that perform a specific task, packaged as a unit. This unit 
> can then be used in programs wherever that particular task should be 
> performed."
> "In different programming languages, a subroutine may be called ... a 
> function ..."
> "In the C and C++ programming languages, subprograms are termed functions.".
> 
> How does your definition for the term "subroutine" differ from that one, 
> in a way that allows you to exclude C functions?

The generic Computer Science term "subroutine" (although I suspect
that the term "subroutine" was used way earlier than the term
"Computer Science") just means that you can re-use code by calling
it from various places and having control (optionally) return back
to the code that called it (The called routine could always call
exit() or abort() rather than return, or just never return).  That
Wikipedia article describes the concept fairly well.

It doesn't matter whether there is any kind of return value(s), or
whether there are parameters.  It doesn't require any specialized
assembly instructions (like "call" and "return" or fancier versions
of these).  (OS/360 used "BR 14" as the "return" instruction, where
register 14 was the conventional register to hold the return address.
The caller was responsible for setting that register.) It doesn't
matter whether the subroutine modifies the global state of the
system or whether it always returns the same result for the same
arguments.

About the only thing that it does seem to require is the ability
to branch (at "the return") to a destination related to where it
came from without the code for the subroutine having to know about
all of its possible callers.  This seems to require either:

	(a) A branch instruction that takes its target from some
	kind of variable (e.g. a register, memory that *ISN'T* part
	of an instruction, a stack, or something computed from these
	(base and index registers), etc.) rather than coding it
	into the instruction,
	or 
	(b) The ability to modify an ordinary branch instruction
	with a fixed target to change its target, then execute it.
	Self-modifying code is generally frowned on as a security
	problem and modern operating systems tend to prohibit writing
	on executable code or executing writable memory.  It also
	tends to have problems with thread-safety and recursive
	routines.  Some microcontrollers don't let you even address
	the code space (typically read-only memory) with instructions
	for manipulating data.

The C standard doesn't use the term "subroutine".  The C standard
also doesn't define "bug", either, but you can't use that to convince
me that C code cannot have bugs, nor does it define the term "ugly"
as applied to coding styles or code.

Some other languages (FORTRAN comes to mind, and it's way older
than C) make a distinction between SUBROUTINE and FUNCTION.  FUNCTIONS
returned values, SUBROUTINEs didn't.  This didn't rule out the
possibility of what's often called OUT parameters, or in C it's
"passing in a pointer to an area of memory to be used to return
results").  Trying to apply that definition to C will cause confusion,
depending on how strictly you interpret it.

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


#120377

FromKeith Thompson <kst-u@mib.org>
Date2017-09-27 09:15 -0700
Message-ID<lntvzoyv6u.fsf@kst-u.example.com>
In reply to#120356
David Brown <david.brown@hesbynett.no> writes:
On 26/09/17 13:28, Malcolm McLean wrote:
[...]
>> But you're using a subroutine call. 
>
> C does not have subroutines.  I think you mean a function call?

C has subroutines.  It calls them "functions".

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


#120384

Frombartc <bc@freeuk.com>
Date2017-09-27 17:50 +0100
Message-ID<xFQyB.1218936$tN5.1165921@fx27.am4>
In reply to#120377
On 27/09/2017 17:15, Keith Thompson wrote:
> David Brown <david.brown@hesbynett.no> writes:
> On 26/09/17 13:28, Malcolm McLean wrote:
> [...]
>>> But you're using a subroutine call.
>>
>> C does not have subroutines.  I think you mean a function call?
> 
> C has subroutines.  It calls them "functions".

It emulates subroutines, which are procedures that don't return values, 
with functions returning a special 'void' value.

And it doesn't work that well because, if I try and return a value from 
such a function, half the compilers I used either say nothing, or give a 
warning.

It should absolutely be a hard error.

(Unless someone can explain to me how such a thing can be just a warning.)

-- 
bartc

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


#120386

Fromjameskuyper@verizon.net
Date2017-09-27 10:35 -0700
Message-ID<a298b5d0-4df6-4676-84dd-3c7f1f40f574@googlegroups.com>
In reply to#120384
On Wednesday, September 27, 2017 at 12:50:45 PM UTC-4, Bart wrote:
> On 27/09/2017 17:15, Keith Thompson wrote:
...
> > C has subroutines.  It calls them "functions".
> 
> It emulates subroutines, which are procedures that don't return values, 
> with functions returning a special 'void' value.

"The void type comprises an empty set of values;" (6.2.5p19). It is therefore
impossible for a value to be void. Void serves to mark a function as not
returning a value.


> And it doesn't work that well because, if I try and return a value from 
> such a function, half the compilers I used either say nothing,

"A return statement with an expression shall not appear in a function whose
return type is void. A return statement without an expression shall only appear
in a function whose return type is void." (6.8.6.4p1). That occurs in a
Constraints section, so a a diagnostic message is mandatory. Any compiler which
fails to generate one is non-conforming. That is hardly surprising, since you've
adamantly refused to learn what needs to be done to invoke your compilers in
fully-conforming mode.

>  or give a  warning.

As you should know by now, if you had any capacity to understand the relevant
concepts, the strongest requirement that the standard imposes when a conforming
compiler translates code which violates one of the standard's rules, is that at
least one diagnostic message must be generated. A warning message satisfies that
requirement. Anything beyond that is entirely a matter of QoI, and entirely at
the implementor's discretion.

> It should absolutely be a hard error.

If you believe that strongly enough, complain to the implementors of those
compilers.

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


#120388

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-09-27 18:47 +0100
Message-ID<87fub8ghje.fsf@bsb.me.uk>
In reply to#120384
bartc <bc@freeuk.com> writes:

> On 27/09/2017 17:15, Keith Thompson wrote:
>> David Brown <david.brown@hesbynett.no> writes:
>> On 26/09/17 13:28, Malcolm McLean wrote:
>> [...]
>>>> But you're using a subroutine call.
>>>
>>> C does not have subroutines.  I think you mean a function call?
>>
>> C has subroutines.  It calls them "functions".
>
> It emulates subroutines, which are procedures that don't return
> values, with functions returning a special 'void' value.

There is no "special 'void' value" so that explanation can only be
confusing (to people who don't know).  "void functions" are simply C's
way of writing a subroutine or a procedure.  They return no value.

> And it doesn't work that well because, if I try and return a value
> from such a function, half the compilers I used either say nothing, or
> give a warning.

Not this again?  I'm pretty sure you know how to fix this.

-- 
Ben.

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


#120391

Fromsupercat@casperkitty.com
Date2017-09-27 10:52 -0700
Message-ID<425bb609-9b0f-4d3a-88a6-448489789f43@googlegroups.com>
In reply to#120388
On Wednesday, September 27, 2017 at 12:47:42 PM UTC-5, Ben Bacarisse wrote:
> There is no "special 'void' value" so that explanation can only be
> confusing (to people who don't know).  "void functions" are simply C's
> way of writing a subroutine or a procedure.  They return no value.

Failure to recognize the concept of empty objects can add a lot of needless
complexity to a language.  Treating empty objects the same way as any others
can be a useful simplifying abstraction in many cases, though many language
specs are written in a way that makes it needlessly leaky.

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


Page 3 of 10 — ← Prev page 1 2 [3] 4 5 … 10  Next page →

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


csiph-web