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


Groups > comp.lang.c > #77192

Re: qsort() function misunderstanding

From glen herrmannsfeldt <gah@ugcs.caltech.edu>
Newsgroups comp.lang.c
Subject Re: qsort() function misunderstanding
Date 2015-11-25 23:14 +0000
Organization Aioe.org NNTP Server
Message-ID <n35fct$979$1@speranza.aioe.org> (permalink)
References (4 earlier) <n32a8u$a85$1@dont-email.me> <34g95bl1hlooehff2h8g7a8hfmbccfs8e0@4ax.com> <15e660c6-9a01-42d4-aa31-0466dd39eb75@googlegroups.com> <n34b0c$759$1@speranza.aioe.org> <729d46e5-e7ef-457d-a47c-371e03a5cddb@googlegroups.com>

Show all headers | View raw


supercat@casperkitty.com wrote:

(snip of what I wrote about readability)

> A bigger complication is that the name "C" is given to two families 
> of dialects with vastly different philosophies.
 
> As originally conceived, C was a language which would make it possible for a
> simple compiler to yield efficient code by allowing programmers to specify
> things at a somewhat lower level than was typically allowed in other
> languages.  A simple Pascal compiler given:

(snip of example indexing three arrays)
 
> While a better compiler would be able to use loop induction for the address
> calculations, such a compiler would require more computational resources than
> a simple one.  C made it possible to write the code as:
 
>    int *p1 = array1, *p2 = array2, *p3 = array3;
>    i=100;
>    do
>      *p1++ = *p2++ + *p3++;
>    while(--i);
 
> and yield code that would run quickly without the compiler having to do any
> sort of advanced analysis.
 
> Over the years, the kinds of operations that machines can perform efficiently
> have changed.  Some C dialects, especially those used for embedded-systems
> programming, are driven by a philosophy that it's best to define behavior in
> terms of operations performed on memory, and say that programmers can use
> any algorithmic optimization techniques that would be applicable given such
> a view.

More moved than changed. The things you say were done by big computers
at that time, but not small ones.

At least IBM S/360 has indexing modes that can easily do that,
and Fortran H was known to figure that out in only 256K or core.
(That is little ferrite doughnuts with wires through them.)

But more recently people working with Herucles wanted to run gcc
on MVS on emulated IBM S/370 with only a 16M address space, and
probably 8M left for the user program. But gcc won't run, at least
won't compile itself, in 8M. The art of small compilers is lost.

It doesn't take all that big a compiler to figure out array
indexing, though. 

> Other dialects, however, take the viewpoint that it's better to say that if
> a program uses constructs in ways that the language committee viewed as
> "dubious", compilers should have no obligation to generate code that behaves
> in any particular fashion.  The philosophy is that such rules will give good
> compilers more opportunities to optimize code, and the value of such
> optimizations will exceed the value of any optimizations a programmer could
> produce.

OK, I have agreed with this for a while now.
 
> Personally, I wish proponents of both philosophies could reconcile their
> differences and realize that for different kinds of processors and
> programming the relative costs to the programmer or compiler for semantic
> concessions, and the value of those concessions to the other party, will
> vary enormously, and adding a means within the language to indicate what
> semantics are actually required would allow code to achieve even better
> performance than is available under the present rules, while allowing the
> full range of semantic possibilities that can be achieved with the "simple
> compiler" philosophy.

For smaller processors, everyone uses cross compilers, so the need
for users to write optimal, and less readable, code is gone.

-- glen

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-24 01:48 -0800
  Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-24 10:32 +0000
    Re: qsort() function misunderstanding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-24 11:08 +0000
      Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-24 12:03 +0000
        Re: qsort() function misunderstanding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-24 16:12 +0000
    Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-24 03:33 -0800
      Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-24 12:05 +0000
        Re: qsort() function misunderstanding glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-24 13:52 +0000
          Re: qsort() function misunderstanding Ken Brody <kenbrody@spamcop.net> - 2015-11-24 10:01 -0500
        Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-24 06:04 -0800
          Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-24 14:16 +0000
      Re: qsort() function misunderstanding James Kuyper <jameskuyper@verizon.net> - 2015-11-24 07:32 -0500
        Re: qsort() function misunderstanding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-24 16:43 +0000
          Re: qsort() function misunderstanding glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-25 05:58 +0000
            Re: qsort() function misunderstanding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-25 11:34 +0000
              Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-25 12:45 +0000
                Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-26 02:18 -0800
                Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-26 10:45 +0000
              Re: qsort() function misunderstanding glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-25 14:46 +0000
          Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-25 00:51 -0800
            Re: qsort() function misunderstanding James Kuyper <jameskuyper@verizon.net> - 2015-11-25 08:12 -0500
              Re: qsort() function misunderstanding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-25 14:02 +0000
                Re: qsort() function misunderstanding James Kuyper <jameskuyper@verizon.net> - 2015-11-25 11:37 -0500
                Re: qsort() function misunderstanding Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-25 17:36 +0000
  Re: qsort() function misunderstanding Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-24 03:30 -0800
    Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-24 03:48 -0800
      Re: qsort() function misunderstanding Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-24 06:29 -0800
    pre/post increments (was Re: qsort() function misunderstanding) Ken Brody <kenbrody@spamcop.net> - 2015-11-24 09:55 -0500
  Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-24 06:06 -0800
  Re: qsort() function misunderstanding Barry Schwarz <schwarzb@dqel.com> - 2015-11-24 07:33 -0800
  Re: qsort() function misunderstanding Keith Thompson <kst-u@mib.org> - 2015-11-24 09:04 -0800
    Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-24 17:17 +0000
      Re: qsort() function misunderstanding Geoff <geoff@invalid.invalid> - 2015-11-24 10:03 -0800
        Re: qsort() function misunderstanding Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-24 13:31 -0500
          Re: qsort() function misunderstanding Geoff <geoff@invalid.invalid> - 2015-11-24 12:34 -0800
            Re: qsort() function misunderstanding Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-24 16:02 -0500
              Re: qsort() function misunderstanding supercat@casperkitty.com - 2015-11-24 15:18 -0800
                Re: qsort() function misunderstanding Chad <cdalten@gmail.com> - 2015-11-24 16:15 -0800
                Re: qsort() function misunderstanding Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-24 23:51 -0800
            Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-25 01:01 -0800
              Re: qsort() function misunderstanding glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-25 12:53 +0000
                Re: qsort() function misunderstanding supercat@casperkitty.com - 2015-11-25 10:15 -0800
                Re: qsort() function misunderstanding glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-25 23:14 +0000
                Re: qsort() function misunderstanding supercat@casperkitty.com - 2015-11-25 16:33 -0800
                Re: qsort() function misunderstanding glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-26 08:18 +0000
      Re: qsort() function misunderstanding Ian Collins <ian-news@hotmail.com> - 2015-11-25 10:41 +1300
        Re: qsort() function misunderstanding Richard Heathfield <rjh@cpax.org.uk> - 2015-11-24 22:08 +0000
    Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-25 00:53 -0800
  Re: qsort() function misunderstanding Alla _ <modelling.data@gmail.com> - 2015-11-25 09:07 -0800

csiph-web