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


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

Re: C String terminator

Started byTim Rentsch <tr.17687@z991.linuxsc.com>
First post2020-02-16 02:25 -0800
Last post2020-04-09 07:38 -0700
Articles 20 on this page of 148 — 20 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-16 02:25 -0800
    Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-16 14:24 -0800
      Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-22 08:13 -0800
        Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-22 09:05 -0800
          Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-03-27 19:58 -0700
            Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-03-27 23:26 -0700
              Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-02 09:21 -0700
                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-02 09:54 -0700
                  Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-02 11:17 -0700
                    Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-02 13:12 -0700
                      Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-02 13:28 -0700
                  Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-02 19:17 -0700
                    Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-03 09:47 +0200
                      Re: C String terminator already5chosen@yahoo.com - 2020-04-03 08:03 -0700
                        Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-03 17:34 +0200
                          Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-03 12:39 -0400
                          Re: C String terminator Bart <bc@freeuk.com> - 2020-04-03 18:05 +0100
                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-03 10:18 -0700
                              Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-03 22:13 +0100
                                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-03 14:36 -0700
                                  Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-03 16:18 -0700
                                    Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-04 01:43 -0700
                                      Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-04 18:23 +0200
                                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-04 11:18 -0700
                                          Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-04 13:02 -0700
                                          Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-05 21:54 +0200
                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-05 13:59 -0700
                                              Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-06 09:07 +0200
                                                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 02:25 -0700
                                                  Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-06 11:43 +0100
                                                    Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 03:56 -0700
                                                      Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-06 16:34 +0100
                                                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 10:30 -0700
                                                          Re: C String terminator richard@cogsci.ed.ac.uk (Richard Tobin) - 2020-04-06 17:50 +0000
                                                          Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-06 11:31 -0700
                                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 12:04 -0700
                                                          Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-06 21:51 +0100
                                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 14:34 -0700
                                                              Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-06 14:39 -0700
                                                                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-06 14:52 -0700
                                                                  Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-06 15:31 -0700
                                                                  Re: C String terminator jameskuyper@stellarscience.com - 2020-04-06 16:05 -0700
                                                              Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-07 03:08 +0100
                                                                Re: C String terminator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2020-04-06 21:12 -0600
                                                                  Re: C String terminator scott@slp53.sl.home (Scott Lurndal) - 2020-04-07 16:55 +0000
                                                                    Re: C String terminator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2020-04-07 11:05 -0600
                                                                      Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-07 20:39 +0200
                                                                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 11:48 -0700
                                                                          Re: C String terminator Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2020-04-07 21:21 -0600
                                                                          Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-07 20:40 -0700
                                                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-08 01:41 -0700
                                                                              Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-08 07:40 -0700
                                                                                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-08 08:16 -0700
                                                                                  Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-08 09:17 -0700
                                                                                    Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-08 09:46 -0700
                                                                                      Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-08 10:37 -0700
                                                                                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-08 10:48 -0700
                                                                                          Re: C String terminator Richard Damon <Richard@Damon-Family.org> - 2020-04-08 14:07 -0400
                                                                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-08 11:29 -0700
                                                                                          Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-08 16:46 -0700
                                                                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-09 01:57 -0700
                                                                                              Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-09 08:42 -0700
                                                                                                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-09 08:56 -0700
                                                                                                  Re: C String terminator Richard Damon <Richard@Damon-Family.org> - 2020-04-09 12:42 -0400
                                                                                                    Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-09 10:12 -0700
                                                                                                      Re: C String terminator Richard Damon <Richard@Damon-Family.org> - 2020-04-09 15:51 -0400
                                                                                                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-09 13:02 -0700
                                                                                                      Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-09 13:06 -0700
                                                                                                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-09 14:49 -0700
                                                                                                          Re: C String terminator Richard Damon <Richard@Damon-Family.org> - 2020-04-09 19:05 -0400
                                                                                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-10 02:25 -0700
                                                                                                              Re: C String terminator Öö Tiib <ootiib@hot.ee> - 2020-04-10 04:38 -0700
                                                                                                                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-10 05:21 -0700
                                                                                                                  Re: C String terminator Öö Tiib <ootiib@hot.ee> - 2020-04-10 07:13 -0700
                                                                                                                    Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-10 11:38 -0700
                                                                                                                      Re: C String terminator Ike Naar <ike@sdf.lonestar.org> - 2020-04-11 17:38 +0000
                                                                                                                        Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-11 15:04 -0700
                                                                                                                      Re: C String terminator Richard Damon <Richard@Damon-Family.org> - 2020-04-11 15:16 -0400
                                                                                                                        Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-11 21:45 +0100
                                                                                                                          Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-12 04:39 -0700
                                                                                                                            Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-12 21:34 +0100
                                                                                                                              Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-12 14:38 -0700
                                                                                                                            Re: C String terminator Richard Damon <Richard@Damon-Family.org> - 2020-04-13 11:13 -0400
                                                                                                                              Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-13 08:24 -0700
                                                                                                                        Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-11 15:08 -0700
                                                                                                  Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-09 09:53 -0700
                                                                    Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-07 14:35 -0400
                                                                Re: C String terminator Öö Tiib <ootiib@hot.ee> - 2020-04-06 21:04 -0700
                                                                  Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 01:16 -0700
                                                                    Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-07 02:08 -0700
                                                                      Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 02:19 -0700
                                                                        Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-07 08:42 -0700
                                                                          Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 10:39 -0700
                                                                            Re: C String terminator scott@slp53.sl.home (Scott Lurndal) - 2020-04-07 17:45 +0000
                                                                              Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-07 14:40 -0400
                                                                            Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-07 11:03 -0700
                                                                              Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 11:14 -0700
                                                                                Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-07 12:19 -0700
                                                                    Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-07 12:02 +0100
                                                                    Re: C String terminator Öö Tiib <ootiib@hot.ee> - 2020-04-07 06:27 -0700
                                                                      Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 07:44 -0700
                                                                        Re: C String terminator Öö Tiib <ootiib@hot.ee> - 2020-04-07 08:30 -0700
                                                                Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 00:27 -0700
                                                                  Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-07 12:50 +0100
                                                                    Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-07 05:25 -0700
                                                                      Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-07 23:52 +0100
                                                                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-08 03:15 -0700
                                                                          Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-08 21:28 +0100
                                                                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-08 15:40 -0700
                                                                              Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-09 00:31 +0100
                                                                  Re: C String terminator Ike Naar <ike@sdf.lonestar.org> - 2020-04-07 21:40 +0000
                                                      Re: C String terminator luser droog <luser.droog@gmail.com> - 2020-04-06 09:41 -0700
                                                  Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-06 12:46 -0700
                                                  Re: C String terminator Guillaume <message@bottle.org> - 2020-04-07 17:17 +0200
                                                    Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-09 07:23 -0700
                                        Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-04 22:32 +0100
                            Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-03 21:59 +0200
                              Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-03 23:48 -0400
                                Jared Kushner would be proud... (Was: C String terminator) gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-04 09:00 +0000
                                  Re: Jared Kushner would be proud... (Was: C String terminator) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-04 02:45 -0700
                                    Re: Jared Kushner would be proud... (Was: C String terminator) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-04-04 10:24 +0000
                                      Re: Jared Kushner would be proud... (Was: C String terminator) Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-04 03:55 -0700
                                        Re: Jared Kushner would be proud... Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-04 13:27 -0700
                                          Re: Jared Kushner would be proud... Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-04 13:52 -0700
                                            Re: Jared Kushner would be proud... Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-04 14:12 -0700
                                              Re: Jared Kushner would be proud... Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-04 15:12 -0700
                                            Re: Jared Kushner would be proud... Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-04 15:03 -0700
                                            Re: Jared Kushner would be proud... Richard Damon <Richard@Damon-Family.org> - 2020-04-04 18:46 -0400
                                              Re: Jared Kushner would be proud... Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-05 01:53 -0700
                                                Re: Jared Kushner would be proud... Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-05 02:33 -0700
                                                  Re: Jared Kushner would be proud... Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-05 06:43 -0700
                                      Re: Jared Kushner would be proud... (Was: C String terminator) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-04 19:48 -0700
                                    Re: Jared Kushner would be proud... (Was: C String terminator) James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-04 06:37 -0700
                                Re: C String terminator David Brown <david.brown@hesbynett.no> - 2020-04-04 18:36 +0200
                                Re: C String terminator dave_thompson_2@comcast.net - 2020-05-02 15:13 -0400
                        Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-03 09:41 -0700
                          Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-03 10:33 -0700
                            Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-03 11:14 -0700
                              Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-03 11:34 -0700
                            Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-03 14:48 -0400
                              Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-03 12:10 -0700
                                Re: C String terminator Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-03 13:24 -0700
                                  Re: C String terminator James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-03 23:59 -0400
                          Re: C String terminator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-03 22:05 +0100
                        Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-04 20:34 -0700
                          Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-05 02:05 -0700
                            Re: C String terminator Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-09 07:35 -0700
                              Re: C String terminator Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-04-09 07:38 -0700

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


#151247

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-09 01:57 -0700
Message-ID<89841304-79c4-43a3-9bec-d5eab27c4a08@googlegroups.com>
In reply to#151244
On Thursday, 9 April 2020 00:47:10 UTC+1, James Kuyper  wrote:
> On Wednesday, April 8, 2020 at 1:48:28 PM UTC-4, Malcolm McLean wrote:
>
> What, precisely, is it you're claiming to have said "earlier upstream"?
>
I made the point that you can implement IO by using absolute addresses,
on some hardware.
>
> That it is in fact possible for "volatile" to have an effect in code 
> that uses only core language facilities? That's what I'm saying, that 
> you're responding "Yes" to.
> If so, the why did you follow up at a later time, by saying "volatile 
> ... can't have any effect unless you use non-core language facilities"?
> 
Volatile only has an effect if, for instance, we write a 'a' to the 
volatile object, there's an interrupt that read it, then we write a 
'b'. Ohterwise it's the same as non-volatile data. But we can't generate
the interrupt using just the core language, though we can probably set 
an "interrupt routine" using an extension.

I suppose you could argue that this is doing IO.

void writebytes(volatile int *port)
{

   volatile int busycounter;
   *port = 'a';
   for(busycouter = 0; busycounter < 100; busycounter++);
   *port = 'b';
}

Then we call it

writebytes((volatile int *) 0x12345678);

And it's just using the core language because you are passing in the
absolute address rather than calculating it in the function, and
you rely on a non-portabe assumption about the characteristics of
the memory at that region.

That's another case of what I'm going to get onto. Parameterising
your IO rather than supplying it as subroutines.

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


#151265

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2020-04-09 08:42 -0700
Message-ID<d4e22be3-b1ce-42ed-b768-98f98d2d07e9@googlegroups.com>
In reply to#151247
On Thursday, April 9, 2020 at 4:58:09 AM UTC-4, Malcolm McLean wrote:
> On Thursday, 9 April 2020 00:47:10 UTC+1, James Kuyper  wrote:
> > On Wednesday, April 8, 2020 at 1:48:28 PM UTC-4, Malcolm McLean wrote:
> >
> > What, precisely, is it you're claiming to have said "earlier upstream"?
> >
> I made the point that you can implement IO by using absolute addresses,
> on some hardware.

OK - that I missed. So my follow-up question remains: why did you
follow up at a later time, by saying "volatile ... can't have any
effect unless you use non-core language facilities"? I guess that
the answer is your assumption, explained below, that interrupts
must be invoked to make that happen:

> > That it is in fact possible for "volatile" to have an effect in code 
> > that uses only core language facilities? That's what I'm saying, that 
> > you're responding "Yes" to.
> > If so, the why did you follow up at a later time, by saying "volatile 
> > ... can't have any effect unless you use non-core language facilities"?
> > 
> Volatile only has an effect if, for instance, we write a 'a' to the 
> volatile object, there's an interrupt that read it, then we write a 
> 'b'. Ohterwise it's the same as non-volatile data. But we can't generate
> the interrupt using just the core language, though we can probably set 
> an "interrupt routine" using an extension.

You might be talking about the way some particular
implementations of C actually work. I'm talking about what's
allowed by the standard. The standard imposes no such
requirement. A conforming implementation of C is allowed to cause
(input from/output to) a device as the immediate consequence of
(reading from/writing to) a specific piece of memory through a
volatile-qualified lvalue without requiring that the code use
non-core language features to trigger an interrupt. 

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


#151266

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-09 08:56 -0700
Message-ID<fccb1674-e35e-4f8a-ba85-2296d9e6f638@googlegroups.com>
In reply to#151265
On Thursday, 9 April 2020 16:42:13 UTC+1, James Kuyper  wrote:
> On Thursday, April 9, 2020 at 4:58:09 AM UTC-4, Malcolm McLean wrote:
>
> OK - that I missed. So my follow-up question remains: why did you
> follow up at a later time, by saying "volatile ... can't have any
> effect unless you use non-core language facilities"? I guess that
> the answer is your assumption, explained below, that interrupts
> must be invoked to make that happen:
>
Making data volatile means "something outside of the current thread
may read / write this", or, in the case of a delay loop, "don't optimise this
away". However using core C, there's no way to create the "something
outside of the current thread". Even the delay loop can't be guaranteed
because theres no requirement on how long any operation should take,
though I suppose you could say you are guaranteed N instructions.

Interrupts are an example of something that might access volatile
memory. The interrupt service routine and the main routine can both
be written in core C, but they can't be set up in that relationship. 
 >
> You might be talking about the way some particular
> implementations of C actually work. I'm talking about what's
> allowed by the standard. The standard imposes no such
> requirement. A conforming implementation of C is allowed to cause
> (input from/output to) a device as the immediate consequence of
> (reading from/writing to) a specific piece of memory through a
> volatile-qualified lvalue without requiring that the code use
> non-core language features to trigger an interrupt.
>
Yes, but you need to obtain an address from somewhere to do memory 
mapped IO. You can't do that with the core language. It might be
an absolute address, or it might be an address obtained from
an operating system call, but that step has to occur somewhere.

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


#151268

FromRichard Damon <Richard@Damon-Family.org>
Date2020-04-09 12:42 -0400
Message-ID<3gIjG.348315$mJ2.342434@fx23.iad>
In reply to#151266
On 4/9/20 11:56 AM, Malcolm McLean wrote:
> On Thursday, 9 April 2020 16:42:13 UTC+1, James Kuyper  wrote:
>> On Thursday, April 9, 2020 at 4:58:09 AM UTC-4, Malcolm McLean wrote:
>>
>> OK - that I missed. So my follow-up question remains: why did you
>> follow up at a later time, by saying "volatile ... can't have any
>> effect unless you use non-core language facilities"? I guess that
>> the answer is your assumption, explained below, that interrupts
>> must be invoked to make that happen:
>>
> Making data volatile means "something outside of the current thread
> may read / write this", or, in the case of a delay loop, "don't optimise this
> away". However using core C, there's no way to create the "something
> outside of the current thread". Even the delay loop can't be guaranteed
> because theres no requirement on how long any operation should take,
> though I suppose you could say you are guaranteed N instructions.
> 
> Interrupts are an example of something that might access volatile
> memory. The interrupt service routine and the main routine can both
> be written in core C, but they can't be set up in that relationship. 
>  >

You may not be able to do it portably, but you CAN do it (on some
machines) using just the core features of C. Without using extensions,
you need a machine with the right characteristics, like the address of
the ISR needs to be able to be written into the memory mapped control
register of the interrupt controller.

Of course, the mere mention of interrupts means we are dealing in a
non-portable space, because machines do interrupts in very different
manners (including not having them at all).

>> You might be talking about the way some particular
>> implementations of C actually work. I'm talking about what's
>> allowed by the standard. The standard imposes no such
>> requirement. A conforming implementation of C is allowed to cause
>> (input from/output to) a device as the immediate consequence of
>> (reading from/writing to) a specific piece of memory through a
>> volatile-qualified lvalue without requiring that the code use
>> non-core language features to trigger an interrupt.
>>
> Yes, but you need to obtain an address from somewhere to do memory 
> mapped IO. You can't do that with the core language. It might be
> an absolute address, or it might be an address obtained from
> an operating system call, but that step has to occur somewhere.
> 

What is non-core about

  *(volatile unsigned char*)(0x1234) = 5;

Yes, it isn't portable, but by DEFINITION I/O will involve
non-portablility, as machines differ. The only way to make I/O portable
is to greatly restrict the machines you will support, which when talking
portability is sort of cheating.

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


#151270

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-09 10:12 -0700
Message-ID<730c5155-f371-4c0d-985d-ca0e845878d4@googlegroups.com>
In reply to#151268
On Thursday, 9 April 2020 17:42:48 UTC+1, Richard Damon  wrote:
> On 4/9/20 11:56 AM, Malcolm McLean wrote:
>  
> What is non-core about
> 
>   *(volatile unsigned char*)(0x1234) = 5;
> 
> Yes, it isn't portable, but by DEFINITION I/O will involve
> non-portablility, as machines differ. The only way to make I/O portable
> is to greatly restrict the machines you will support, which when talking
> portability is sort of cheating.
>
Exactly. So saying "does IO vs does not do IO" is almost exactly
the same thing as saying "non-portable vs can be made portable".

They're two different ways of looking at the same distinction.

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


#151276

FromRichard Damon <Richard@Damon-Family.org>
Date2020-04-09 15:51 -0400
Message-ID<e1LjG.138235$UC6.74102@fx09.iad>
In reply to#151270
On 4/9/20 1:12 PM, Malcolm McLean wrote:
> On Thursday, 9 April 2020 17:42:48 UTC+1, Richard Damon  wrote:
>> On 4/9/20 11:56 AM, Malcolm McLean wrote:
>>  
>> What is non-core about
>>
>>   *(volatile unsigned char*)(0x1234) = 5;
>>
>> Yes, it isn't portable, but by DEFINITION I/O will involve
>> non-portablility, as machines differ. The only way to make I/O portable
>> is to greatly restrict the machines you will support, which when talking
>> portability is sort of cheating.
>>
> Exactly. So saying "does IO vs does not do IO" is almost exactly
> the same thing as saying "non-portable vs can be made portable".
> 
> They're two different ways of looking at the same distinction.
> 

Except that not all non-I/O operations are portable.

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


#151277

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-09 13:02 -0700
Message-ID<ee592c58-16a0-44dc-b7b5-6814e3775343@googlegroups.com>
In reply to#151276
On Thursday, 9 April 2020 20:51:50 UTC+1, Richard Damon  wrote:
> On 4/9/20 1:12 PM, Malcolm McLean wrote:
> > On Thursday, 9 April 2020 17:42:48 UTC+1, Richard Damon  wrote:
> >> On 4/9/20 11:56 AM, Malcolm McLean wrote:
> >>  
> >> What is non-core about
> >>
> >>   *(volatile unsigned char*)(0x1234) = 5;
> >>
> >> Yes, it isn't portable, but by DEFINITION I/O will involve
> >> non-portablility, as machines differ. The only way to make I/O portable
> >> is to greatly restrict the machines you will support, which when talking
> >> portability is sort of cheating.
> >>
> > Exactly. So saying "does IO vs does not do IO" is almost exactly
> > the same thing as saying "non-portable vs can be made portable".
> > 
> > They're two different ways of looking at the same distinction.
> > 
> 
> Except that not all non-I/O operations are portable.
>
Like clearing the cache, for example.

So it's only "almost exactly the same thing". Not a tautology.

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


#151278

FromJames Kuyper <jameskuyper@alumni.caltech.edu>
Date2020-04-09 13:06 -0700
Message-ID<3aaa1e27-88f4-4134-bd9c-539f7a72fb8e@googlegroups.com>
In reply to#151270
On Thursday, April 9, 2020 at 1:12:39 PM UTC-4, Malcolm McLean wrote:
> On Thursday, 9 April 2020 17:42:48 UTC+1, Richard Damon  wrote:
> > On 4/9/20 11:56 AM, Malcolm McLean wrote:
> >  
> > What is non-core about
> > 
> >   *(volatile unsigned char*)(0x1234) = 5;
> > 
> > Yes, it isn't portable, but by DEFINITION I/O will involve
> > non-portablility, as machines differ. The only way to make I/O portable
> > is to greatly restrict the machines you will support, which when talking
> > portability is sort of cheating.
> >
> Exactly. So saying "does IO vs does not do IO" is almost exactly
> the same thing as saying "non-portable vs can be made portable".

It's impossible to do I/O without involving something non-portable. All
C I/O has behavior that is defined in terms of reading/writing bytes,
and the size of a byte is implementation-defined. There's lots of other
I/O portability issues (including just about every detail of the
representation of types and the encoding of characters), but byte size
is one that's guaranteed to apply to any program that does I/O.

However it doesn't work the other way. There's lots of ways in which
code can be non-portable that don't involve I/O in any  way, shape, or
form. Annex J is titled "Portability Issues", is 28 pages long, and most
of the issues listed there have nothing to do with I/O. In particular, the byte size, type representation, and character encoding issues I mentioned above can all cause portability issues for a program that doesn't do any I/O at all.

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


#151281

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-09 14:49 -0700
Message-ID<ca367c35-c5a6-4f02-843c-39ac48feb5f3@googlegroups.com>
In reply to#151278
On Thursday, 9 April 2020 21:06:25 UTC+1, James Kuyper  wrote:
> On Thursday, April 9, 2020 at 1:12:39 PM UTC-4, Malcolm McLean wrote:
> >
> It's impossible to do I/O without involving something non-portable. All
> C I/O has behavior that is defined in terms of reading/writing bytes,
> and the size of a byte is implementation-defined. There's lots of other
> I/O portability issues (including just about every detail of the
> representation of types and the encoding of characters), but byte size
> is one that's guaranteed to apply to any program that does I/O.
>
That is a gotcha, though unlikely to be an issue in practice.  
>
> However it doesn't work the other way. There's lots of ways in which
> code can be non-portable that don't involve I/O in any  way, shape, or
> form. Annex J is titled "Portability Issues", is 28 pages long, and 
> most of the issues listed there have nothing to do with I/O. In 
> particular, the byte size, type representation, and character encoding 
> issues I mentioned above can all cause portability issues for a program 
> that doesn't do any I/O at all.
>
You certainly can have "portability issues". But you can overcome
most of them. Sometimes you have to define operations in terms of
C types rather than bits for practical and efficiency reasons, and
sometimes that causes genuine real world problems which can't be 
overcome. But minimising those situations is one of the points of 
all of this.

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


#151282

FromRichard Damon <Richard@Damon-Family.org>
Date2020-04-09 19:05 -0400
Message-ID<zSNjG.610250$db6.414807@fx33.iad>
In reply to#151281
On 4/9/20 5:49 PM, Malcolm McLean wrote:
> On Thursday, 9 April 2020 21:06:25 UTC+1, James Kuyper  wrote:
>> On Thursday, April 9, 2020 at 1:12:39 PM UTC-4, Malcolm McLean wrote:
>>>
>> It's impossible to do I/O without involving something non-portable. All
>> C I/O has behavior that is defined in terms of reading/writing bytes,
>> and the size of a byte is implementation-defined. There's lots of other
>> I/O portability issues (including just about every detail of the
>> representation of types and the encoding of characters), but byte size
>> is one that's guaranteed to apply to any program that does I/O.
>>
> That is a gotcha, though unlikely to be an issue in practice.  
>>
>> However it doesn't work the other way. There's lots of ways in which
>> code can be non-portable that don't involve I/O in any  way, shape, or
>> form. Annex J is titled "Portability Issues", is 28 pages long, and 
>> most of the issues listed there have nothing to do with I/O. In 
>> particular, the byte size, type representation, and character encoding 
>> issues I mentioned above can all cause portability issues for a program 
>> that doesn't do any I/O at all.
>>
> You certainly can have "portability issues". But you can overcome
> most of them. Sometimes you have to define operations in terms of
> C types rather than bits for practical and efficiency reasons, and
> sometimes that causes genuine real world problems which can't be 
> overcome. But minimising those situations is one of the points of 
> all of this.
> 

But getting back to your original thesis, that there was something
important about distinguishing between your definition of a function and
a procedure that was so important, you wanted to confusingly use a word
with a very standard meaning in the C programming community. That
somehow it is important to distinguish between routines that include
doing I/O in there operation, and those that don't, as if there is
something fundamentally different.

A question, Does a function suddenly become a procedure if the memory it
writes to becomes visible, like in a display buffer of a video card?

How about if the memory it is writing to isn't directly the display
buffer, but something has setup a DMA channel to periodically copy the
memory to a display buffer?

If the difference intentional or not, does it need to know that it is
doing I/O to be a procedure?

How about a program specially crafted to generate EMI that can be heard
on a radio, is that a function or a procedure? How about if the EMI
isn't intentional but someone is using it to try to reverse engineer
something about the program?

Suddenly I don't see a whole lot of ground to use to draw a line between
your functions and procedures, there is a lot of muddled ground in between.

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


#151285

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-10 02:25 -0700
Message-ID<9c2efce8-e36e-477d-b768-c412d658b6fa@googlegroups.com>
In reply to#151282
On Friday, 10 April 2020 00:05:12 UTC+1, Richard Damon  wrote:
> 
> But getting back to your original thesis, that there was something
> important about distinguishing between your definition of a function and
> a procedure that was so important, you wanted to confusingly use a word
> with a very standard meaning in the C programming community. That
> somehow it is important to distinguish between routines that include
> doing I/O in there operation, and those that don't, as if there is
> something fundamentally different.
>
We can't just say "IO versus not IO" or "portable verus non-portable"
without a lot of qualification, because of these problems.  
>
> A question, Does a function suddenly become a procedure if the memory it
> writes to becomes visible, like in a display buffer of a video card?
> 
> How about if the memory it is writing to isn't directly the display
> buffer, but something has setup a DMA channel to periodically copy the
> memory to a display buffer?
> 
> If the difference intentional or not, does it need to know that it is
> doing I/O to be a procedure?
> 
> How about a program specially crafted to generate EMI that can be heard
> on a radio, is that a function or a procedure? How about if the EMI
> isn't intentional but someone is using it to try to reverse engineer
> something about the program?
> 
> Suddenly I don't see a whole lot of ground to use to draw a line between
> your functions and procedures, there is a lot of muddled ground in between.
>
Firstly, there's this idea that words denote mathematical sets, or they
are useless. That's of course untrue. If we say "tall" there's not a
set of men who are tall versus a set of men who are non-tall, instead
we have some men who are clearly tall, some who are clearly non-tall,
and some who are marginal. 

Similarly, the vast majority of code that people writes either "does
something" or "calculates something". The distinction is usually
completely unproblematic. But now we have these marginal cases.

What if you pass a display buffer to a function? Is it a "calculating"
or "doing". After all, it's mapping one set of bits to another set 
of bits, so it meets the definition of "a mathematical function"
does it not? So maybe we need some sort of fancy defintion to state
that all bits must be equivalent. We can't use a loose term like
"their location must not matter" because we allow globals.

Truth is it really doesn't matter, because if you are writing directly
to a disply buffer, your fucntion is unlikely to be useful outside
of that specific platform, even if it can in theory be written
enitely portable, because it is agnostic about the actual location
of the buffer. So it doesn't really matter how you classify it, it
could reasonably go in both and not much is lost.

However what does blow the thing wide open is "what happens when
you parameterise your IO?". What happens id you perform IO via
an indirect call verus a direct call?

However don't lose sight of the fact that you can do an awful lot
by simply mapping bits to bits.
  

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


#151286

FromÖö Tiib <ootiib@hot.ee>
Date2020-04-10 04:38 -0700
Message-ID<bfcc2697-013d-4478-a27d-ccf637fca746@googlegroups.com>
In reply to#151285
On Friday, 10 April 2020 12:25:42 UTC+3, Malcolm McLean  wrote:
> On Friday, 10 April 2020 00:05:12 UTC+1, Richard Damon  wrote:
> > 
> > But getting back to your original thesis, that there was something
> > important about distinguishing between your definition of a function and
> > a procedure that was so important, you wanted to confusingly use a word
> > with a very standard meaning in the C programming community. That
> > somehow it is important to distinguish between routines that include
> > doing I/O in there operation, and those that don't, as if there is
> > something fundamentally different.
> >
> We can't just say "IO versus not IO" or "portable verus non-portable"
> without a lot of qualification, because of these problems.  
> >
> > A question, Does a function suddenly become a procedure if the memory it
> > writes to becomes visible, like in a display buffer of a video card?
> > 
> > How about if the memory it is writing to isn't directly the display
> > buffer, but something has setup a DMA channel to periodically copy the
> > memory to a display buffer?
> > 
> > If the difference intentional or not, does it need to know that it is
> > doing I/O to be a procedure?
> > 
> > How about a program specially crafted to generate EMI that can be heard
> > on a radio, is that a function or a procedure? How about if the EMI
> > isn't intentional but someone is using it to try to reverse engineer
> > something about the program?
> > 
> > Suddenly I don't see a whole lot of ground to use to draw a line between
> > your functions and procedures, there is a lot of muddled ground in between.
> >
> Firstly, there's this idea that words denote mathematical sets, or they
> are useless. That's of course untrue. If we say "tall" there's not a
> set of men who are tall versus a set of men who are non-tall, instead
> we have some men who are clearly tall, some who are clearly non-tall,
> and some who are marginal. 
> 
> Similarly, the vast majority of code that people writes either "does
> something" or "calculates something". The distinction is usually
> completely unproblematic. But now we have these marginal cases.
> 
> What if you pass a display buffer to a function? Is it a "calculating"
> or "doing". After all, it's mapping one set of bits to another set 
> of bits, so it meets the definition of "a mathematical function"
> does it not? So maybe we need some sort of fancy defintion to state
> that all bits must be equivalent. We can't use a loose term like
> "their location must not matter" because we allow globals.
> 
> Truth is it really doesn't matter, because if you are writing directly
> to a disply buffer, your fucntion is unlikely to be useful outside
> of that specific platform, even if it can in theory be written
> enitely portable, because it is agnostic about the actual location
> of the buffer. So it doesn't really matter how you classify it, it
> could reasonably go in both and not much is lost.

Is portability to other platforms the only reason why those 
"Malcolm functions" and "Malcolm procedures" are alleged
to be useful distinction? If to look at portable frameworks
then that does not seem to be case as those often do lot of I/O.

> However what does blow the thing wide open is "what happens when
> you parameterise your IO?". What happens id you perform IO via
> an indirect call verus a direct call?

What that typically means is that we have some kind of
filters, checkers, correctors, converters and/or the like 
integrated into or layered between doing I/O. An what happens 
is that some kind of common filtering, checking, conversion 
and/or the like is done during I/O and so usually making it
simpler and more robust to use. What did blow wide open?

> However don't lose sight of the fact that you can do an awful lot
> by simply mapping bits to bits.

That is true therefore pure functions are useful distinction.
That has not much to do with portability. Pure functions are
just simpler for people to reason about and also for tools
to analyze, validate and optimize. So keeping the parts of
program that are possible to write as pure free of impurities
herds the complications into fewer locations in code.

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


#151287

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-10 05:21 -0700
Message-ID<e0024275-6d30-47ec-ae6c-e8a6bd9c291a@googlegroups.com>
In reply to#151286
On Friday, 10 April 2020 12:38:17 UTC+1, Öö Tiib  wrote:
> On Friday, 10 April 2020 12:25:42 UTC+3, Malcolm McLean  wrote:
>
> Is portability to other platforms the only reason why those 
> "Malcolm functions" and "Malcolm procedures" are alleged
> to be useful distinction? If to look at portable frameworks
> then that does not seem to be case as those often do lot of I/O.
>
No, it's also an attempt to improve the logical structure and
arragement of programs. Portability is a bonus.
> 
> > However what does blow the thing wide open is "what happens when
> > you parameterise your IO?". What happens id you perform IO via
> > an indirect call verus a direct call?
> 
> What that typically means is that we have some kind of
> filters, checkers, correctors, converters and/or the like 
> integrated into or layered between doing I/O. An what happens 
> is that some kind of common filtering, checking, conversion 
> and/or the like is done during I/O and so usually making it
> simpler and more robust to use. What did blow wide open?
>
If you don't allow parameterised IO, then you can ask "does
this code do IO or doesn't it?" and get a clear distinction, once
you've decided exactly what you call "IO". Once you parameterise
IO, you can always make the IO routine in fact read and write
from memory, and sometimes it makes sense to do that. 
 
> > However don't lose sight of the fact that you can do an awful lot
> > by simply mapping bits to bits.
> 
> That is true therefore pure functions are useful distinction.
> That has not much to do with portability. Pure functions are
> just simpler for people to reason about and also for tools
> to analyze, validate and optimize. So keeping the parts of
> program that are possible to write as pure free of impurities
> herds the complications into fewer locations in code.
>
The distinction between pure functions and non-pure functions
is certainly useful and that is generally accepted. I'm saying
the the distinction between functions that calculate things and
functions that do things is also useful. I'm not saying that when
you make this distinction, it is no longer useful to make a
disnction between pure and impure functions within the "functions
that calculate things".

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


#151290

FromÖö Tiib <ootiib@hot.ee>
Date2020-04-10 07:13 -0700
Message-ID<4b9b90a0-0393-41de-8857-1f8e379e4d79@googlegroups.com>
In reply to#151287
On Friday, 10 April 2020 15:22:06 UTC+3, Malcolm McLean  wrote:
> On Friday, 10 April 2020 12:38:17 UTC+1, Öö Tiib  wrote:
> > On Friday, 10 April 2020 12:25:42 UTC+3, Malcolm McLean  wrote:
> >
> > Is portability to other platforms the only reason why those 
> > "Malcolm functions" and "Malcolm procedures" are alleged
> > to be useful distinction? If to look at portable frameworks
> > then that does not seem to be case as those often do lot of I/O.
> >
> No, it's also an attempt to improve the logical structure and
> arragement of programs. Portability is a bonus.

I was asking because you were seemingly claiming that when 
some used bits are originating from memory mapped input and/or 
some altered bits go into memory mapped output then it somehow
does not matter because the code is likely platform specific.
However purity and portability seem to be orthogonal properties
of code and correlation seems incidental.

> > 
> > > However what does blow the thing wide open is "what happens when
> > > you parameterise your IO?". What happens id you perform IO via
> > > an indirect call verus a direct call?
> > 
> > What that typically means is that we have some kind of
> > filters, checkers, correctors, converters and/or the like 
> > integrated into or layered between doing I/O. An what happens 
> > is that some kind of common filtering, checking, conversion 
> > and/or the like is done during I/O and so usually making it
> > simpler and more robust to use. What did blow wide open?
> >
> If you don't allow parameterised IO, then you can ask "does
> this code do IO or doesn't it?" and get a clear distinction, once
> you've decided exactly what you call "IO". Once you parameterise
> IO, you can always make the IO routine in fact read and write
> from memory, and sometimes it makes sense to do that.

All meaningful software has input and output. Basically most
software can be described like input -> processing -> output.
Input can come from multiple, possibly unrelated sources and
output can go to multiple, possibly also unrelated targets
but that it generally is.
  
So when function uses only its parameters (only) for input
and only its return value for output then it is pure. 
It does not matter if its parameters did come from some
(possibly platform specific) external source or return value
is sent to external target it still keeps being pure.

The complications arise from side-effects. Side effects
may result with different output and behavior to same input.
Such complication makes functions harder to test, analyze
optimize and reason about.

>  
> > > However don't lose sight of the fact that you can do an awful lot
> > > by simply mapping bits to bits.
> > 
> > That is true therefore pure functions are useful distinction.
> > That has not much to do with portability. Pure functions are
> > just simpler for people to reason about and also for tools
> > to analyze, validate and optimize. So keeping the parts of
> > program that are possible to write as pure free of impurities
> > herds the complications into fewer locations in code.
> >
> The distinction between pure functions and non-pure functions
> is certainly useful and that is generally accepted. I'm saying
> the the distinction between functions that calculate things and
> functions that do things is also useful. I'm not saying that when
> you make this distinction, it is no longer useful to make a
> disnction between pure and impure functions within the "functions
> that calculate things".

And I am saying that only functions that are pure calculate things,
and impure potentially do something or are potentially distracted
by something unrelated to that calculation and so are more difficult
to reason about. ;)

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


#151291

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-10 11:38 -0700
Message-ID<cc8db103-9023-4756-b19d-158077333c30@googlegroups.com>
In reply to#151290
On Friday, 10 April 2020 15:13:20 UTC+1, Öö Tiib  wrote:
> 
> I was asking because you were seemingly claiming that when 
> some used bits are originating from memory mapped input and/or 
> some altered bits go into memory mapped output then it somehow
> does not matter because the code is likely platform specific.
> However purity and portability seem to be orthogonal properties
> of code and correlation seems incidental.
> 
Pure functions can always be written portably. 

Functions which take buffers which happen to be memory mapped can
also be written portably, but aren't pure functions.

Functions which originate the addresses of memory-mapped buffers
must be in some way non-portable, though it might be a single line.

e.g.
unsigned char *raster = 0x80000000; /* screen start address */

However whilst the code that writes into the buffer may be portable,
it's unlikely to be of much use unless a compatible dispaly device
is attached to the computer. 
> 
> So when function uses only its parameters (only) for input
> and only its return value for output then it is pure. 
> It does not matter if its parameters did come from some
> (possibly platform specific) external source or return value
> is sent to external target it still keeps being pure.
>
> The complications arise from side-effects. Side effects
> may result with different output and behavior to same input.
> Such complication makes functions harder to test, analyze
> optimize and reason about.
>
I'm not opposed to pure functions. But I'm distinguishing
different types of "side effects". Which I do by defining the
function's domain in a different way. 
>
> And I am saying that only functions that are pure calculate things,
> and impure potentially do something or are potentially distracted
> by something unrelated to that calculation and so are more difficult
> to reason about. ;)
>
A pure function requires that input and output bits be physically
distinct, and that input bits be described at the point of invocation,
and that output bits be returned to the point of invocation and
nowhere else.
However if you relax these requirements you don't get "just anything".
You get a superset of pure functions, but still quite a narrow one. 
rand() is now included, for example, but not printf().
You are making your functions harder to reason about by not insisting
that every function be pure, I'll agree. 

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


#151292

FromIke Naar <ike@sdf.lonestar.org>
Date2020-04-11 17:38 +0000
Message-ID<slrn3losr94040.61j.ike@sdf.lonestar.org>
In reply to#151291
On 2020-04-10, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
> A pure function requires that input and output bits be physically
> distinct, and that input bits be described at the point of invocation,
> and that output bits be returned to the point of invocation and
> nowhere else.

I don't follow. Let 

  int pure(int arg);

be a pure function, and let

  int var;

be a variable that holds a value such that pure(var) is well-defined.
Are you saying that, if we call the function as follows:

  var = pure(var);

that now suddenly the function is no longer pure because its
input bits and output bits are not distinct? (both are the bits of 'var').

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


#151295

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2020-04-11 15:04 -0700
Message-ID<87h7xpk7c2.fsf@nosuchdomain.example.com>
In reply to#151292
Ike Naar <ike@sdf.lonestar.org> writes:
> On 2020-04-10, Malcolm McLean <malcolm.arthur.mclean@gmail.com> wrote:
>> A pure function requires that input and output bits be physically
>> distinct, and that input bits be described at the point of invocation,
>> and that output bits be returned to the point of invocation and
>> nowhere else.
>
> I don't follow. Let 
>
>   int pure(int arg);
>
> be a pure function, and let
>
>   int var;
>
> be a variable that holds a value such that pure(var) is well-defined.
> Are you saying that, if we call the function as follows:
>
>   var = pure(var);
>
> that now suddenly the function is no longer pure because its
> input bits and output bits are not distinct? (both are the bits of 'var').

I don't think so, and though I can only speculate I don't think
Malcolm thinks so either.

The "input bits" for that call are (the representation of) the
current *value* of var, not the object var.  That value is obtained
via the *lvalue conversion* described in N1570 6.3.2.1p2 before the
function is called.  The "output bits" are (the representation of)
the function's return value.  The storage of those bits in var is
done by the assignment, not by the function call.

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

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


#151293

FromRichard Damon <Richard@Damon-Family.org>
Date2020-04-11 15:16 -0400
Message-ID<2IokG.1296436$ek.27835@fx48.iad>
In reply to#151291
On 4/10/20 2:38 PM, Malcolm McLean wrote:
> On Friday, 10 April 2020 15:13:20 UTC+1, Öö Tiib  wrote:
>>
>> I was asking because you were seemingly claiming that when 
>> some used bits are originating from memory mapped input and/or 
>> some altered bits go into memory mapped output then it somehow
>> does not matter because the code is likely platform specific.
>> However purity and portability seem to be orthogonal properties
>> of code and correlation seems incidental.
>>
> Pure functions can always be written portably. 

Disagree here. The ONLY way you can make such a claim is to restrict
your machine definition to something that isn't efficient. Either you
need to define that all math is to be done in infinite precision
arithmetic (which is inefficient on most machines), has a language
defined precision (sort of like what Java does so that it is inefficient
on any machine that doesn't well match the language specification) or
you get non-portable answers. C was designed for efficiency over
portability, which is one reason it did succeed in its designed market.

This simple question of what is the natural result of 20,000 + 20,000
has two possible answers on common current machines, 40,000 and -25,536
(on a machine with 16 bit integers).

Unless you restrict you class of problems to only those stated so that
they require a portable answer, you have non-portable functions.

Then you get the non-portable functions due to the need for the results
to be suitable for I/O, and you bring in a whole host of other
non-portable conditions (or does the fact that we are thinking about I/O
cross the line and make them procedures?)

> 
> Functions which take buffers which happen to be memory mapped can
> also be written portably, but aren't pure functions.
> 
> Functions which originate the addresses of memory-mapped buffers
> must be in some way non-portable, though it might be a single line.
> 
> e.g.
> unsigned char *raster = 0x80000000; /* screen start address */
> 
> However whilst the code that writes into the buffer may be portable,
> it's unlikely to be of much use unless a compatible dispaly device
> is attached to the computer. 

But by your definition, when we call some function with that parameter,
whether that function actually is a 'function' or a 'procedure' is now
dependent of if that address is an ordinary block of ram, or a display
buffer.
>>
>> So when function uses only its parameters (only) for input
>> and only its return value for output then it is pure. 
>> It does not matter if its parameters did come from some
>> (possibly platform specific) external source or return value
>> is sent to external target it still keeps being pure.
>>
>> The complications arise from side-effects. Side effects
>> may result with different output and behavior to same input.
>> Such complication makes functions harder to test, analyze
>> optimize and reason about.
>>
> I'm not opposed to pure functions. But I'm distinguishing
> different types of "side effects". Which I do by defining the
> function's domain in a different way. 
>>
>> And I am saying that only functions that are pure calculate things,
>> and impure potentially do something or are potentially distracted
>> by something unrelated to that calculation and so are more difficult
>> to reason about. ;)
>>
> A pure function requires that input and output bits be physically
> distinct, and that input bits be described at the point of invocation,
> and that output bits be returned to the point of invocation and
> nowhere else.
> However if you relax these requirements you don't get "just anything".
> You get a superset of pure functions, but still quite a narrow one. 
> rand() is now included, for example, but not printf().
> You are making your functions harder to reason about by not insisting
> that every function be pure, I'll agree. 
> 
> 

Again, we come to the point, does this class of routines, that you want
to 'hijack' the well defined (in C) definition of a function, to use
that same label, and cause all the confusion.

Since this class of functions can access and create all sorts of side
effects (as long as it isn't 'I/O') there is little that an
implementation can do based on knowing that a given routine is or is not
a function of this type.

'Pure functions' can have an important use, as since given exactly the
same parameters they will produce always the exact same output means
that they become available to have their usage optimized, and redundant
calls removed.

I will have to say that I can't recall any significant mentioning by
anyone else of this type of distinction.

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


#151294

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2020-04-11 21:45 +0100
Message-ID<87h7xpn44g.fsf@bsb.me.uk>
In reply to#151293
Richard Damon <Richard@Damon-Family.org> writes:

> On 4/10/20 2:38 PM, Malcolm McLean wrote:
>> On Friday, 10 April 2020 15:13:20 UTC+1, Öö Tiib  wrote:
>>>
>>> I was asking because you were seemingly claiming that when 
>>> some used bits are originating from memory mapped input and/or 
>>> some altered bits go into memory mapped output then it somehow
>>> does not matter because the code is likely platform specific.
>>> However purity and portability seem to be orthogonal properties
>>> of code and correlation seems incidental.
>>>
>> Pure functions can always be written portably. 
>
> Disagree here. The ONLY way you can make such a claim is to restrict
> your machine definition to something that isn't efficient. Either you
> need to define that all math is to be done in infinite precision
> arithmetic (which is inefficient on most machines), has a language
> defined precision (sort of like what Java does so that it is inefficient
> on any machine that doesn't well match the language specification) or
> you get non-portable answers. C was designed for efficiency over
> portability, which is one reason it did succeed in its designed market.

I was debating whether to make this point as well.  MM is a broad-brush
kind of person and I am sure there is some meaning (possibly along the
lines you paint here) that is what was really meant.  Anyway, for what
it's worth, my example was going to be

  unsigned long long bit_set(void)
  {
      return 0x800008000200000020000000800A20AC;
  }

where the author clearly knew that unsigned long long was 128 bits wide.

This function can't be written portably (in the usual sense of the word)
because not all implementations have an 128-bit unsigned type.  The
whole program would need to be re-engineered (quite possible including
some of the I/O library) to use an invented fake 128-bit integer type.
And even that counts as "portable", it's likely that a total re-design
of affected parts would be an better option.

The fact that this function is pure is, to put is mildly, secondary to
the fact that it is very much not portable.

<cut>
> I will have to say that I can't recall any significant mentioning by
> anyone else of this type of distinction.

Me neither.  I'm still baffled why Malcolm thinks it is so important.
(Yes, I know the /stated/ reasons.)

-- 
Ben.

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


#151298

FromMalcolm McLean <malcolm.arthur.mclean@gmail.com>
Date2020-04-12 04:39 -0700
Message-ID<c6ecfa15-23a6-419a-8bbc-e5f9175373b4@googlegroups.com>
In reply to#151294
On Saturday, 11 April 2020 21:45:30 UTC+1, Ben Bacarisse  wrote:
> Richard Damon <Richard@Damon-Family.org> writes:
> 
> > On 4/10/20 2:38 PM, Malcolm McLean wrote:
> >> On Friday, 10 April 2020 15:13:20 UTC+1, 嘱 Tiib  wrote:
> >>>
> >>> I was asking because you were seemingly claiming that when 
> >>> some used bits are originating from memory mapped input and/or 
> >>> some altered bits go into memory mapped output then it somehow
> >>> does not matter because the code is likely platform specific.
> >>> However purity and portability seem to be orthogonal properties
> >>> of code and correlation seems incidental.
> >>>
> >> Pure functions can always be written portably. 
> >
> > Disagree here. The ONLY way you can make such a claim is to restrict
> > your machine definition to something that isn't efficient. Either you
> > need to define that all math is to be done in infinite precision
> > arithmetic (which is inefficient on most machines), has a language
> > defined precision (sort of like what Java does so that it is inefficient
> > on any machine that doesn't well match the language specification) or
> > you get non-portable answers. C was designed for efficiency over
> > portability, which is one reason it did succeed in its designed market.
> 
> I was debating whether to make this point as well.  MM is a broad-brush
> kind of person and I am sure there is some meaning (possibly along the
> lines you paint here) that is what was really meant.  Anyway, for what
> it's worth, my example was going to be
> 
>   unsigned long long bit_set(void)
>   {
>       return 0x800008000200000020000000800A20AC;
>   }
> 
> where the author clearly knew that unsigned long long was 128 bits wide.
> 
> This function can't be written portably (in the usual sense of the word)
> because not all implementations have an 128-bit unsigned type.  The
> whole program would need to be re-engineered (quite possible including
> some of the I/O library) to use an invented fake 128-bit integer type.
> And even that counts as "portable", it's likely that a total re-design
> of affected parts would be an better option.
> 
> The fact that this function is pure is, to put is mildly, secondary to
> the fact that it is very much not portable.
> 
A function maps bits on entry to bits on exit, and if you want to be
100% portable you have to specify it in terms of bits. So yes, you
need to fake up a 128 bit type if you need 128 bit computations. But
you can do that.
Instead of saying "this function must return a C unsigned long that
holds the value 0x800008000200000020000000800A20AC, which is clearly
impossible to achieve portably, we need to say
"this function must map the unit set (an empty list of bits in), to
the set of bits that represent values, choosing the member that
represents the value 0x800008000200000020000000800A20AC".

You then have to provide "the set of bits that represent values", which
depends on the rest of the program.

There's the human-meaningful function you are trying to model, then
there's the C type. Sometimes, though rarely, the C types won't be
up to the task of modelling the human-meaningful function, so you
have to drop down to bits.

To give another example, consider the fucntion "cosine". We could say
the human meaningful function is "this function shall a reasonable
approximation to the cosine of theta, as long as theta is reasonably 
close to the range +/- 2 * PI". Or we could say, "this function shall
return the cosine of theta, adhering exactly to important body standard
this and that".
You can reasonably want either, but if the higher ups demand the second, 
we have a portablity headache. However that won't daunt us. We'll just
download some floating point routines from github, and build the 
function on top of integer operations.

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


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

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


csiph-web