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


Groups > sci.electronics.design > #480507 > unrolled thread

Ping Tom Gardner et. al.

Started bybitrex <bitrex@de.lete.earthlink.net>
First post2017-10-05 20:49 -0400
Last post2017-10-16 11:23 +0200
Articles 18 — 4 participants

Back to article view | Back to sci.electronics.design


Contents

  Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-05 20:49 -0400
    Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 09:36 +0200
      Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 11:18 +0200
        Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 05:59 -0400
          Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 06:05 -0400
            Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 12:20 +0200
      Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 11:47 +0100
        Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 14:24 +0200
          Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 13:55 +0100
            Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 09:12 -0400
              Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 16:37 +0200
              Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 15:50 +0100
                Re: Ping Tom Gardner et. al. bitrex <bitrex@de.lete.earthlink.net> - 2017-10-06 14:02 -0400
            Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-06 16:32 +0200
              Re: Ping Tom Gardner et. al. Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-10-06 17:44 +0100
                Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-16 11:18 +0200
            Re: Ping Tom Gardner et. al. Jasen Betts <jasen@xnet.co.nz> - 2017-10-09 07:58 +0000
              Re: Ping Tom Gardner et. al. David Brown <david.brown@hesbynett.no> - 2017-10-16 11:23 +0200

#480507 — Ping Tom Gardner et. al.

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-10-05 20:49 -0400
SubjectPing Tom Gardner et. al.
Message-ID<kqABB.142601$po2.80988@fx36.iad>
In case you aren't checking the other big thread I started, one more fun 
use of modern C++ on embedded processors I thought might be of interest 
is doing lookup table generation at compile time. Here's some code that 
generates a table for some weird function:

<https://pastebin.com/5jB4RRz4>

(source: 
<http://cplusadd.blogspot.com/2013/02/c11-compile-time-lookup-tablearray-with.html>)

Here's the asm output with gcc 5.3.0 with flags -std=c++11 -Os for the 
MSP430:

<https://pastebin.com/NYkjV9Ra>

Look ma, no code! The compiler just puts a lookup table in the data section.

The output for x86 is even more compact using 64 bit magic numbers and 
offsets. No math.h functions called anywhere:

<https://pastebin.com/4vg0Y49S>

[toc] | [next] | [standalone]


#480551

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-06 09:36 +0200
Message-ID<or7bpu$efd$1@dont-email.me>
In reply to#480507
On 06/10/17 02:49, bitrex wrote:
> In case you aren't checking the other big thread I started, one more fun
> use of modern C++ on embedded processors I thought might be of interest
> is doing lookup table generation at compile time. Here's some code that
> generates a table for some weird function:
> 
> <https://pastebin.com/5jB4RRz4>
> 
> (source:
> <http://cplusadd.blogspot.com/2013/02/c11-compile-time-lookup-tablearray-with.html>)
> 

C++14 allows a lot more freedom in constexpr functions.  In particular,
it lets you write loops.  That means you can do the same sort of thing
with much simpler and clearer code, and with much greater compile-time
efficiency.  These recursive template solutions avoid run-time costs,
but scale very badly when you want larger tables.  You then find
yourself using binary recursion instead of linear recursion, and while
everything works correctly (it's easy to check), your code review folks
are sticking hot pokers in their eyes to avoid looking at it.

So C++11 allows some fancy tricks like, but they should not be used
until C++14 and generalised constexpr functions.  (I can't remember
off-hand if gcc 5.3 supports that - I /think/ it does.)

For lower than C++14, write your table generators in Python - simple,
clear, and you can output a table in C or C++ formats.

> 
> Here's the asm output with gcc 5.3.0 with flags -std=c++11 -Os for the
> MSP430:
> 
> <https://pastebin.com/NYkjV9Ra>
> 
> Look ma, no code! The compiler just puts a lookup table in the data
> section.
> 
> The output for x86 is even more compact using 64 bit magic numbers and
> offsets. No math.h functions called anywhere:
> 
> <https://pastebin.com/4vg0Y49S>

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


#480558

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-06 11:18 +0200
Message-ID<or7hpn$mdb$1@dont-email.me>
In reply to#480551
On 06/10/17 09:36, David Brown wrote:
> On 06/10/17 02:49, bitrex wrote:
>> In case you aren't checking the other big thread I started, one more fun
>> use of modern C++ on embedded processors I thought might be of interest
>> is doing lookup table generation at compile time. Here's some code that
>> generates a table for some weird function:
>>
>> <https://pastebin.com/5jB4RRz4>
>>
>> (source:
>> <http://cplusadd.blogspot.com/2013/02/c11-compile-time-lookup-tablearray-with.html>)
>>
> 
> C++14 allows a lot more freedom in constexpr functions.  In particular,
> it lets you write loops.  That means you can do the same sort of thing
> with much simpler and clearer code, and with much greater compile-time
> efficiency.  These recursive template solutions avoid run-time costs,
> but scale very badly when you want larger tables.  You then find
> yourself using binary recursion instead of linear recursion, and while
> everything works correctly (it's easy to check), your code review folks
> are sticking hot pokers in their eyes to avoid looking at it.
> 
> So C++11 allows some fancy tricks like, but they should not be used
> until C++14 and generalised constexpr functions.  (I can't remember
> off-hand if gcc 5.3 supports that - I /think/ it does.)
> 
> For lower than C++14, write your table generators in Python - simple,
> clear, and you can output a table in C or C++ formats.
> 
>>
>> Here's the asm output with gcc 5.3.0 with flags -std=c++11 -Os for the
>> MSP430:
>>
>> <https://pastebin.com/NYkjV9Ra>
>>
>> Look ma, no code! The compiler just puts a lookup table in the data
>> section.
>>
>> The output for x86 is even more compact using 64 bit magic numbers and
>> offsets. No math.h functions called anywhere:
>>
>> <https://pastebin.com/4vg0Y49S>
> 

When you are trying to look at the code generated for things like this,
avoid std::cout like the plague - it clutters everything up.

Try this code:

#include <cmath>

template<unsigned N>
struct Table {
    double values[N];
    static constexpr unsigned length = N;

    constexpr double& operator[](size_t i) {
        return values[i];
    }
    constexpr const double& operator[](size_t i) const {
        return values[i];
    }
};

template <unsigned N, typename LambdaType>
constexpr Table<N> TableGenerator(LambdaType evalFunc) {
    Table<N> table{};
    for (unsigned i = 0; i < table.length; i++) {
        table[i] = evalFunc(i);
    }
    return table;
}

/** Function that computes a value for each index **/
constexpr double myFunc(unsigned idx) {
  return sin(0.2 * idx) + cos(0.5 * idx);
}

constexpr unsigned length = 100;
// create compile-time table
extern constexpr Table<length> table = TableGenerator<length>(myFunc);


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


#480559

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-10-06 05:59 -0400
Message-ID<duIBB.11$m83.3@fx03.iad>
In reply to#480558
On 10/06/2017 05:18 AM, David Brown wrote:
> On 06/10/17 09:36, David Brown wrote:
>> On 06/10/17 02:49, bitrex wrote:
>>> In case you aren't checking the other big thread I started, one more fun
>>> use of modern C++ on embedded processors I thought might be of interest
>>> is doing lookup table generation at compile time. Here's some code that
>>> generates a table for some weird function:
>>>
>>> <https://pastebin.com/5jB4RRz4>
>>>
>>> (source:
>>> <http://cplusadd.blogspot.com/2013/02/c11-compile-time-lookup-tablearray-with.html>)
>>>
>>
>> C++14 allows a lot more freedom in constexpr functions.  In particular,
>> it lets you write loops.  That means you can do the same sort of thing
>> with much simpler and clearer code, and with much greater compile-time
>> efficiency.  These recursive template solutions avoid run-time costs,
>> but scale very badly when you want larger tables.  You then find
>> yourself using binary recursion instead of linear recursion, and while
>> everything works correctly (it's easy to check), your code review folks
>> are sticking hot pokers in their eyes to avoid looking at it.
>>
>> So C++11 allows some fancy tricks like, but they should not be used
>> until C++14 and generalised constexpr functions.  (I can't remember
>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>
>> For lower than C++14, write your table generators in Python - simple,
>> clear, and you can output a table in C or C++ formats.
>>
>>>
>>> Here's the asm output with gcc 5.3.0 with flags -std=c++11 -Os for the
>>> MSP430:
>>>
>>> <https://pastebin.com/NYkjV9Ra>
>>>
>>> Look ma, no code! The compiler just puts a lookup table in the data
>>> section.
>>>
>>> The output for x86 is even more compact using 64 bit magic numbers and
>>> offsets. No math.h functions called anywhere:
>>>
>>> <https://pastebin.com/4vg0Y49S>
>>
> 
> When you are trying to look at the code generated for things like this,
> avoid std::cout like the plague - it clutters everything up.

The problem is at high optimization levels unless you actually _do_ 
something with the table in "main" that has some kind of side-effect the 
compiler just expunges it as well. The most efficient code is nothing!

IDK if there's some way to modify the sources you or I pasted using say 
"volatile" to avoid that and still have it apply heavy optimization

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


#480560

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-10-06 06:05 -0400
Message-ID<FzIBB.724$8%2.58@fx08.iad>
In reply to#480559
On 10/06/2017 05:59 AM, bitrex wrote:
> On 10/06/2017 05:18 AM, David Brown wrote:
>> On 06/10/17 09:36, David Brown wrote:
>>> On 06/10/17 02:49, bitrex wrote:
>>>> In case you aren't checking the other big thread I started, one more 
>>>> fun
>>>> use of modern C++ on embedded processors I thought might be of interest
>>>> is doing lookup table generation at compile time. Here's some code that
>>>> generates a table for some weird function:
>>>>
>>>> <https://pastebin.com/5jB4RRz4>
>>>>
>>>> (source:
>>>> <http://cplusadd.blogspot.com/2013/02/c11-compile-time-lookup-tablearray-with.html>) 
>>>>
>>>>
>>>
>>> C++14 allows a lot more freedom in constexpr functions.  In particular,
>>> it lets you write loops.  That means you can do the same sort of thing
>>> with much simpler and clearer code, and with much greater compile-time
>>> efficiency.  These recursive template solutions avoid run-time costs,
>>> but scale very badly when you want larger tables.  You then find
>>> yourself using binary recursion instead of linear recursion, and while
>>> everything works correctly (it's easy to check), your code review folks
>>> are sticking hot pokers in their eyes to avoid looking at it.
>>>
>>> So C++11 allows some fancy tricks like, but they should not be used
>>> until C++14 and generalised constexpr functions.  (I can't remember
>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>>
>>> For lower than C++14, write your table generators in Python - simple,
>>> clear, and you can output a table in C or C++ formats.
>>>
>>>>
>>>> Here's the asm output with gcc 5.3.0 with flags -std=c++11 -Os for the
>>>> MSP430:
>>>>
>>>> <https://pastebin.com/NYkjV9Ra>
>>>>
>>>> Look ma, no code! The compiler just puts a lookup table in the data
>>>> section.
>>>>
>>>> The output for x86 is even more compact using 64 bit magic numbers and
>>>> offsets. No math.h functions called anywhere:
>>>>
>>>> <https://pastebin.com/4vg0Y49S>
>>>
>>
>> When you are trying to look at the code generated for things like this,
>> avoid std::cout like the plague - it clutters everything up.
> 
> The problem is at high optimization levels unless you actually _do_ 
> something with the table in "main" that has some kind of side-effect the 
> compiler just expunges it as well. The most efficient code is nothing!
> 
> IDK if there's some way to modify the sources you or I pasted using say 
> "volatile" to avoid that and still have it apply heavy optimization

The code you pasted does seem to generate the table by its lonesome for 
the MSP430 using gcc 5.3. I guess it's architecture and table-size 
dependent; x86-64 doesn't because for a table of that size it's using 
magic constants immediate-loaded into registers and not even using the 
.data section at all.

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


#480563

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-06 12:20 +0200
Message-ID<or7leb$gol$1@dont-email.me>
In reply to#480560
On 06/10/17 12:05, bitrex wrote:
> On 10/06/2017 05:59 AM, bitrex wrote:
>> On 10/06/2017 05:18 AM, David Brown wrote:
>>> On 06/10/17 09:36, David Brown wrote:
>>>> On 06/10/17 02:49, bitrex wrote:
>>>>> In case you aren't checking the other big thread I started, one
>>>>> more fun
>>>>> use of modern C++ on embedded processors I thought might be of
>>>>> interest
>>>>> is doing lookup table generation at compile time. Here's some code
>>>>> that
>>>>> generates a table for some weird function:
>>>>>
>>>>> <https://pastebin.com/5jB4RRz4>
>>>>>
>>>>> (source:
>>>>> <http://cplusadd.blogspot.com/2013/02/c11-compile-time-lookup-tablearray-with.html>)
>>>>>
>>>>>
>>>>
>>>> C++14 allows a lot more freedom in constexpr functions.  In particular,
>>>> it lets you write loops.  That means you can do the same sort of thing
>>>> with much simpler and clearer code, and with much greater compile-time
>>>> efficiency.  These recursive template solutions avoid run-time costs,
>>>> but scale very badly when you want larger tables.  You then find
>>>> yourself using binary recursion instead of linear recursion, and while
>>>> everything works correctly (it's easy to check), your code review folks
>>>> are sticking hot pokers in their eyes to avoid looking at it.
>>>>
>>>> So C++11 allows some fancy tricks like, but they should not be used
>>>> until C++14 and generalised constexpr functions.  (I can't remember
>>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>>>
>>>> For lower than C++14, write your table generators in Python - simple,
>>>> clear, and you can output a table in C or C++ formats.
>>>>
>>>>>
>>>>> Here's the asm output with gcc 5.3.0 with flags -std=c++11 -Os for the
>>>>> MSP430:
>>>>>
>>>>> <https://pastebin.com/NYkjV9Ra>
>>>>>
>>>>> Look ma, no code! The compiler just puts a lookup table in the data
>>>>> section.
>>>>>
>>>>> The output for x86 is even more compact using 64 bit magic numbers and
>>>>> offsets. No math.h functions called anywhere:
>>>>>
>>>>> <https://pastebin.com/4vg0Y49S>
>>>>
>>>
>>> When you are trying to look at the code generated for things like this,
>>> avoid std::cout like the plague - it clutters everything up.
>>
>> The problem is at high optimization levels unless you actually _do_
>> something with the table in "main" that has some kind of side-effect
>> the compiler just expunges it as well. The most efficient code is
>> nothing!
>>
>> IDK if there's some way to modify the sources you or I pasted using
>> say "volatile" to avoid that and still have it apply heavy optimization
> 
> The code you pasted does seem to generate the table by its lonesome for
> the MSP430 using gcc 5.3. I guess it's architecture and table-size
> dependent; x86-64 doesn't because for a table of that size it's using
> magic constants immediate-loaded into registers and not even using the
> .data section at all.

The compiler will generate the same table here - whether you target the
msp430 or the x86, compiler version, and optimisation levels (you may
have to change "size_t" to "unsigned" in some cases, however).  The
trick is to use the "-c" flag to tell gcc to compile, but not link the
code.  If you put in a "main" function and add linking, the compiler can
try to see what is /actually/ used and then omit things as needed.  But
when you compile a single translation unit, and include something that
is "exported" - has external linkage - the compiler will generate
appropriate code or data.  So in my example here I have "extern
constexpr Table<length> table = ..." .  This tells the compiler that
other modules may access "table" - it has to generate it.

And the table will be put in .rodata, not .data - on the msp430, that
will be linked into flash, not ram.



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


#480564

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2017-10-06 11:47 +0100
Message-ID<2bJBB.1080790$uh.251387@fx28.am4>
In reply to#480551
On 06/10/17 08:36, David Brown wrote:
> and while
> everything works correctly (it's easy to check), your code review folks
> are sticking hot pokers in their eyes to avoid looking at it.

And that, in a nutshell, is one problem with C/C++


> So C++11 allows some fancy tricks like, but they should not be used
> until C++14 and generalised constexpr functions.  (I can't remember
> off-hand if gcc 5.3 supports that - I /think/ it does.)

And that, in a nutshell, is one recurring problem with C/C++

Choose your poison carefully :)

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


#480567

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-06 14:24 +0200
Message-ID<or7slj$5lc$1@dont-email.me>
In reply to#480564
On 06/10/17 12:47, Tom Gardner wrote:
> On 06/10/17 08:36, David Brown wrote:
>> and while
>> everything works correctly (it's easy to check), your code review folks
>> are sticking hot pokers in their eyes to avoid looking at it.
> 
> And that, in a nutshell, is one problem with C/C++
> 

There are two solutions to it.  One is that when a feature appears
useful but cumbersome, C++ evolves to make it simpler.  Examples include
recursive template programming (replaced by variadic templates and
generalised constexpr functions), the safe boolean idiom (replaced by
explicit conversion operators), and "enable_if" templates (replaced by
concepts).

(If those terms don't mean anything to you, you should question how
valid your opinions on C++ are without knowledge of the modern language.)

The other solution is to realise that you can program in C++ without
understanding all the fiddly and complex bits - you can leave those to
the folks writing libraries.  This is the same in most programming
languages.

> 
>> So C++11 allows some fancy tricks like, but they should not be used
>> until C++14 and generalised constexpr functions.  (I can't remember
>> off-hand if gcc 5.3 supports that - I /think/ it does.)
> 
> And that, in a nutshell, is one recurring problem with C/C++

If you want to use modern features, use a modern compiler.  I don't
track all features and all versions of gcc in my head - but I know how
to look it up.  It is not hard.

> 
> Choose your poison carefully :)

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


#480568

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2017-10-06 13:55 +0100
Message-ID<N2LBB.452713$dT2.429787@fx05.am4>
In reply to#480567
On 06/10/17 13:24, David Brown wrote:
> On 06/10/17 12:47, Tom Gardner wrote:
>> On 06/10/17 08:36, David Brown wrote:
>>> and while
>>> everything works correctly (it's easy to check), your code review folks
>>> are sticking hot pokers in their eyes to avoid looking at it.
>>
>> And that, in a nutshell, is one problem with C/C++
>>
>
> There are two solutions to it.  One is that when a feature appears
> useful but cumbersome, C++ evolves to make it simpler.  Examples include
> recursive template programming (replaced by variadic templates and
> generalised constexpr functions), the safe boolean idiom (replaced by
> explicit conversion operators), and "enable_if" templates (replaced by
> concepts).
>
> (If those terms don't mean anything to you, you should question how
> valid your opinions on C++ are without knowledge of the modern language.)
>
> The other solution is to realise that you can program in C++ without
> understanding all the fiddly and complex bits - you can leave those to
> the folks writing libraries.  This is the same in most programming
> languages.

Just so.

But that doesn't affect the point; C++ descends into being
a write-only state more easily than other equally powerful
languages.

Yes, it is entirely possible to write code that is clear,
simple, and easy to read. Not everybody achieves that.


>>> So C++11 allows some fancy tricks like, but they should not be used
>>> until C++14 and generalised constexpr functions.  (I can't remember
>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>
>> And that, in a nutshell, is one recurring problem with C/C++
>
> If you want to use modern features, use a modern compiler.  I don't
> track all features and all versions of gcc in my head - but I know how
> to look it up.  It is not hard.

The real nasty is that frequently C/C++ compilers
implement /a/ subset of a standard, where the subset
depends on what is convenient and what the compiler
writers understand.

ISTR a triumphant announcement that the first complete
C++ compiler was available, 4/5/6 years after the
standard was published.


>> Choose your poison carefully :)

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


#480569

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-10-06 09:12 -0400
Message-ID<OiLBB.2$y63.0@fx14.iad>
In reply to#480568
On 10/06/2017 08:55 AM, Tom Gardner wrote:
> On 06/10/17 13:24, David Brown wrote:
>> On 06/10/17 12:47, Tom Gardner wrote:
>>> On 06/10/17 08:36, David Brown wrote:
>>>> and while
>>>> everything works correctly (it's easy to check), your code review folks
>>>> are sticking hot pokers in their eyes to avoid looking at it.
>>>
>>> And that, in a nutshell, is one problem with C/C++
>>>
>>
>> There are two solutions to it.  One is that when a feature appears
>> useful but cumbersome, C++ evolves to make it simpler.  Examples include
>> recursive template programming (replaced by variadic templates and
>> generalised constexpr functions), the safe boolean idiom (replaced by
>> explicit conversion operators), and "enable_if" templates (replaced by
>> concepts).
>>
>> (If those terms don't mean anything to you, you should question how
>> valid your opinions on C++ are without knowledge of the modern language.)
>>
>> The other solution is to realise that you can program in C++ without
>> understanding all the fiddly and complex bits - you can leave those to
>> the folks writing libraries.  This is the same in most programming
>> languages.
> 
> Just so.
> 
> But that doesn't affect the point; C++ descends into being
> a write-only state more easily than other equally powerful
> languages.
> 
> Yes, it is entirely possible to write code that is clear,
> simple, and easy to read. Not everybody achieves that.
> 
> 
>>>> So C++11 allows some fancy tricks like, but they should not be used
>>>> until C++14 and generalised constexpr functions.  (I can't remember
>>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>>
>>> And that, in a nutshell, is one recurring problem with C/C++
>>
>> If you want to use modern features, use a modern compiler.  I don't
>> track all features and all versions of gcc in my head - but I know how
>> to look it up.  It is not hard.
> 
> The real nasty is that frequently C/C++ compilers
> implement /a/ subset of a standard, where the subset
> depends on what is convenient and what the compiler
> writers understand.
> 
> ISTR a triumphant announcement that the first complete
> C++ compiler was available, 4/5/6 years after the
> standard was published.
> 
> 
>>> Choose your poison carefully :)
> 
> 

I'm a somewhat younger man that some of the guys here, and I learned the 
rudiments of "professional" coding in college in the mid 1990s.

Is it just me or did PC tech in that era really suck? Like a lot worse 
than what came before or what came after? I remember working with the 
tools available at the time: C90, Lisp, Win95, Mac OS 7/whatever as 
being an enormously painful experience, certainly more so than writing 
BASIC for an Apple II in elementary school, and compared to now there's 
no contest.

Felt like we were trying to do too much with too little.

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


#480584

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-06 16:37 +0200
Message-ID<or84f7$22i$1@dont-email.me>
In reply to#480569
On 06/10/17 15:12, bitrex wrote:

> 
> I'm a somewhat younger man that some of the guys here, and I learned the
> rudiments of "professional" coding in college in the mid 1990s.
> 
> Is it just me or did PC tech in that era really suck? Like a lot worse
> than what came before or what came after? I remember working with the
> tools available at the time: C90, Lisp, Win95, Mac OS 7/whatever as
> being an enormously painful experience, certainly more so than writing
> BASIC for an Apple II in elementary school, and compared to now there's
> no contest.

The days of DOS + Windows dominance were the dark ages of computing.  It
was a shock for me going from networked *nix systems (SunOS and Solaris)
at university, and having to use the shite that was DOS and 16-bit
Windows.  Linux dragged Windows kicking and screaming into the modern
world for developers.  As I understand it, Windows 10 now even has
rudimentary support for multiple workspaces - only 30 years behind *nix!

> 
> Felt like we were trying to do too much with too little.

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


#480586

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2017-10-06 15:50 +0100
Message-ID<SKMBB.1082038$uh.100932@fx28.am4>
In reply to#480569
On 06/10/17 14:12, bitrex wrote:
> On 10/06/2017 08:55 AM, Tom Gardner wrote:
>> On 06/10/17 13:24, David Brown wrote:
>>> On 06/10/17 12:47, Tom Gardner wrote:
>>>> On 06/10/17 08:36, David Brown wrote:
>>>>> and while
>>>>> everything works correctly (it's easy to check), your code review folks
>>>>> are sticking hot pokers in their eyes to avoid looking at it.
>>>>
>>>> And that, in a nutshell, is one problem with C/C++
>>>>
>>>
>>> There are two solutions to it.  One is that when a feature appears
>>> useful but cumbersome, C++ evolves to make it simpler.  Examples include
>>> recursive template programming (replaced by variadic templates and
>>> generalised constexpr functions), the safe boolean idiom (replaced by
>>> explicit conversion operators), and "enable_if" templates (replaced by
>>> concepts).
>>>
>>> (If those terms don't mean anything to you, you should question how
>>> valid your opinions on C++ are without knowledge of the modern language.)
>>>
>>> The other solution is to realise that you can program in C++ without
>>> understanding all the fiddly and complex bits - you can leave those to
>>> the folks writing libraries.  This is the same in most programming
>>> languages.
>>
>> Just so.
>>
>> But that doesn't affect the point; C++ descends into being
>> a write-only state more easily than other equally powerful
>> languages.
>>
>> Yes, it is entirely possible to write code that is clear,
>> simple, and easy to read. Not everybody achieves that.
>>
>>
>>>>> So C++11 allows some fancy tricks like, but they should not be used
>>>>> until C++14 and generalised constexpr functions.  (I can't remember
>>>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>>>
>>>> And that, in a nutshell, is one recurring problem with C/C++
>>>
>>> If you want to use modern features, use a modern compiler.  I don't
>>> track all features and all versions of gcc in my head - but I know how
>>> to look it up.  It is not hard.
>>
>> The real nasty is that frequently C/C++ compilers
>> implement /a/ subset of a standard, where the subset
>> depends on what is convenient and what the compiler
>> writers understand.
>>
>> ISTR a triumphant announcement that the first complete
>> C++ compiler was available, 4/5/6 years after the
>> standard was published.
>>
>>
>>>> Choose your poison carefully :)
>>
>>
>
> I'm a somewhat younger man that some of the guys here, and I learned the
> rudiments of "professional" coding in college in the mid 1990s.
>
> Is it just me or did PC tech in that era really suck? Like a lot worse than what
> came before or what came after? I remember working with the tools available at
> the time: C90, Lisp, Win95, Mac OS 7/whatever as being an enormously painful
> experience, certainly more so than writing BASIC for an Apple II in elementary
> school, and compared to now there's no contest.
>
> Felt like we were trying to do too much with too little.

Interesting question.

I started embedded programming in C in the early 80s when
there were precisely two books on it. It was perfectly
reasonable.

In the late 80s, C++ offered too few advantages over C
to be interesting; Objective-C and Smalltalk had
advantages, albeit in different domains.

In the early 90s I had a brief look at C/C++ for /very/
simple Windows-level programming (i.e. the Petzold
book), had a little go, and then decided that life was
too short to spend doing that kind of <expletive deleted>.
By contrast networking (wired, wireless, telecom) was
much more fun and stimulating.

I kept a watching eye on the newsgroups to see what was
happening to the languages, and was unpleasantly surprised by
the contradictory directions the language was being pulled in.

I would have been happy if it had become a better embedded
language exclusive-or a better applications level language,
but they tried to do both.

I also observed that papers on C/C++ tended to refer /only/
to other C/C++ papers; it was as if the rest of the computing
world didn't exist.

The Java came along, and that was excellent at the applications
level. I was astounded at how quickly excellent mutually-compatible
libraries became available, something that the C/C++ mob had
largely failed to achieve in a decade.

It was notable that Gosling's Java whitepaper gathered many
concepts from many different languages, and selected /only/
those that were field-proven /and/ mutually enhanced each other,
and discarded the rest.

By comparison, the C/C++ mob didn't want to prevent anything,
so had concentrated on creating what the Germans disparagingly
term an "eierlegende Wollmilchsau", i.e. an egg-laying
wool-milk-sow.

Recently returning to embedded programming, I was both
delighted and horrified at how little has changed since
the late 80s.

So yes, I do think C/C++ things in the early 90s were
painful in some respects. Fortunately people were able to
move to tools which didn't hinder them.

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


#480599

Frombitrex <bitrex@de.lete.earthlink.net>
Date2017-10-06 14:02 -0400
Message-ID<QyPBB.152127$wI2.2950@fx41.iad>
In reply to#480586
On 10/06/2017 10:50 AM, Tom Gardner wrote:

>> I'm a somewhat younger man that some of the guys here, and I learned the
>> rudiments of "professional" coding in college in the mid 1990s.
>>
>> Is it just me or did PC tech in that era really suck? Like a lot worse 
>> than what
>> came before or what came after? I remember working with the tools 
>> available at
>> the time: C90, Lisp, Win95, Mac OS 7/whatever as being an enormously 
>> painful
>> experience, certainly more so than writing BASIC for an Apple II in 
>> elementary
>> school, and compared to now there's no contest.
>>
>> Felt like we were trying to do too much with too little.
> 
> Interesting question.
> 
> I started embedded programming in C in the early 80s when
> there were precisely two books on it. It was perfectly
> reasonable.
> 
> In the late 80s, C++ offered too few advantages over C
> to be interesting; Objective-C and Smalltalk had
> advantages, albeit in different domains.
> 
> In the early 90s I had a brief look at C/C++ for /very/
> simple Windows-level programming (i.e. the Petzold
> book), had a little go, and then decided that life was
> too short to spend doing that kind of <expletive deleted>.
> By contrast networking (wired, wireless, telecom) was
> much more fun and stimulating.
> 
> I kept a watching eye on the newsgroups to see what was
> happening to the languages, and was unpleasantly surprised by
> the contradictory directions the language was being pulled in.
> 
> I would have been happy if it had become a better embedded
> language exclusive-or a better applications level language,
> but they tried to do both.
> 
> I also observed that papers on C/C++ tended to refer /only/
> to other C/C++ papers; it was as if the rest of the computing
> world didn't exist.
> 
> The Java came along, and that was excellent at the applications
> level. I was astounded at how quickly excellent mutually-compatible
> libraries became available, something that the C/C++ mob had
> largely failed to achieve in a decade.
> 
> It was notable that Gosling's Java whitepaper gathered many
> concepts from many different languages, and selected /only/
> those that were field-proven /and/ mutually enhanced each other,
> and discarded the rest.
> 
> By comparison, the C/C++ mob didn't want to prevent anything,
> so had concentrated on creating what the Germans disparagingly
> term an "eierlegende Wollmilchsau", i.e. an egg-laying
> wool-milk-sow.
> 
> Recently returning to embedded programming, I was both
> delighted and horrified at how little has changed since
> the late 80s.
> 
> So yes, I do think C/C++ things in the early 90s were
> painful in some respects. Fortunately people were able to
> move to tools which didn't hinder them.


I hadn't thought much about C++ for the better part of 15 years and then 
recently came back to it. I decided to ignore the history and just get 
some books and read articles that focused on C++11 and later and "modern 
C++ design."

Realizing "Oh right, OOP isn't really about classes and big inheritance 
hierarchies and virtualization" and all that stuff which was considered 
hot stuff in the 1990s helped a lot.

By wiping the slate and coming at it fresh and starting immediately with 
the new features like smart pointers, variadic templates, braced 
initalization, constexpr functions etc. it doesn't feel at all like same 
language I was messing around with back then.

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


#480583

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-06 16:32 +0200
Message-ID<or8464$vdb$1@dont-email.me>
In reply to#480568
On 06/10/17 14:55, Tom Gardner wrote:
> On 06/10/17 13:24, David Brown wrote:
>> On 06/10/17 12:47, Tom Gardner wrote:
>>> On 06/10/17 08:36, David Brown wrote:
>>>> and while
>>>> everything works correctly (it's easy to check), your code review folks
>>>> are sticking hot pokers in their eyes to avoid looking at it.
>>>
>>> And that, in a nutshell, is one problem with C/C++
>>>
>>
>> There are two solutions to it.  One is that when a feature appears
>> useful but cumbersome, C++ evolves to make it simpler.  Examples include
>> recursive template programming (replaced by variadic templates and
>> generalised constexpr functions), the safe boolean idiom (replaced by
>> explicit conversion operators), and "enable_if" templates (replaced by
>> concepts).
>>
>> (If those terms don't mean anything to you, you should question how
>> valid your opinions on C++ are without knowledge of the modern language.)
>>
>> The other solution is to realise that you can program in C++ without
>> understanding all the fiddly and complex bits - you can leave those to
>> the folks writing libraries.  This is the same in most programming
>> languages.
> 
> Just so.
> 
> But that doesn't affect the point; C++ descends into being
> a write-only state more easily than other equally powerful
> languages.

1. I know of no languages with the breadth of features, the breadth of
programming styles, and the breadth of target application types, than
C++.  I don't know what you could compare it to here.

2. All languages are write only when you are not familiar with them, or
at least with similar languages.

3. A skilled obfuscater can write write-only code in any language quite
easily.

> 
> Yes, it is entirely possible to write code that is clear,
> simple, and easy to read. Not everybody achieves that.
> 

Not everybody is a good programmer.  Not even all professional
programmers are good programmers.

It is fair to say that as it is a bigger language, it takes longer to be
a good C++ programmer than a good C programmer.  It is perhaps also fair
to say that for the same reason, a bad C++ programmer can make a bigger
mess than a bad C programmer.  But I have seen enough bad C code to know
that a small language does not mean clearer or better code.

> 
>>>> So C++11 allows some fancy tricks like, but they should not be used
>>>> until C++14 and generalised constexpr functions.  (I can't remember
>>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>>
>>> And that, in a nutshell, is one recurring problem with C/C++
>>
>> If you want to use modern features, use a modern compiler.  I don't
>> track all features and all versions of gcc in my head - but I know how
>> to look it up.  It is not hard.
> 
> The real nasty is that frequently C/C++ compilers
> implement /a/ subset of a standard, where the subset
> depends on what is convenient and what the compiler
> writers understand.

There is no "real nasty" about it.  It usually takes time between a
standard being published, and compilers having full support for it.  If
you want to write code that requires C++14, you can look at the
documentation for your compiler and version to see if it supports it.
And you give the compiler a command-line flag to match.  If you want to
compile C++14 code with gcc, you write "g++ -std=c++14" or "g++
-std=gnu++14" (for gcc extensions).  If the compiler does not support
it, it tells you.  If you want experimental partial support for newer
features, look up the flags to enable that.

Both C and C++ standards go to extraordinary lengths to support backward
compatibility, so that old code still works with newer compilers and
newer standards.

> 
> ISTR a triumphant announcement that the first complete
> C++ compiler was available, 4/5/6 years after the
> standard was published.

The first C++ compiler (Cfront from 1983) was available long before the
first C++ standard was published (C++98, in 1998).  The first unofficial
sort-of-standard was the 1985 book "The C++ Programming Language".  gcc
supported C++ from 1987.

In the early days of C++, it took a while for new features to be
properly implemented on a range of compilers.  They are a lot better
now.  The serious C++ compilers (gcc, clang, MSVC, EDG front end) all
have full support for C++14.  gcc and clang have full support for C++17
(which was finished a few months ago, but I think is still not
officially published).


> 
> 
>>> Choose your poison carefully :)
> 
> 

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


#480596

FromTom Gardner <spamjunk@blueyonder.co.uk>
Date2017-10-06 17:44 +0100
Message-ID<%pOBB.1635444$tu4.530213@fx35.am4>
In reply to#480583
On 06/10/17 15:32, David Brown wrote:
> On 06/10/17 14:55, Tom Gardner wrote:
>> On 06/10/17 13:24, David Brown wrote:
>>> On 06/10/17 12:47, Tom Gardner wrote:
>>>> On 06/10/17 08:36, David Brown wrote:
>>>>> and while
>>>>> everything works correctly (it's easy to check), your code review folks
>>>>> are sticking hot pokers in their eyes to avoid looking at it.
>>>>
>>>> And that, in a nutshell, is one problem with C/C++
>>>>
>>>
>>> There are two solutions to it.  One is that when a feature appears
>>> useful but cumbersome, C++ evolves to make it simpler.  Examples include
>>> recursive template programming (replaced by variadic templates and
>>> generalised constexpr functions), the safe boolean idiom (replaced by
>>> explicit conversion operators), and "enable_if" templates (replaced by
>>> concepts).
>>>
>>> (If those terms don't mean anything to you, you should question how
>>> valid your opinions on C++ are without knowledge of the modern language.)
>>>
>>> The other solution is to realise that you can program in C++ without
>>> understanding all the fiddly and complex bits - you can leave those to
>>> the folks writing libraries.  This is the same in most programming
>>> languages.
>>
>> Just so.
>>
>> But that doesn't affect the point; C++ descends into being
>> a write-only state more easily than other equally powerful
>> languages.
>
> 1. I know of no languages with the breadth of features, the breadth of
> programming styles, and the breadth of target application types, than
> C++.  I don't know what you could compare it to here.

No single language, of course - but I regard that as
unimportant. Similarly I would have no interest in a
hammer that also extruded glue.

C/C++ has the bad taste to aim at being what the Germans
disparagingly term an "eierlegende Wollmilchsau", i.e.
an egg-laying wool-milk-sow.


> 2. All languages are write only when you are not familiar with them, or
> at least with similar languages.
>
> 3. A skilled obfuscater can write write-only code in any language quite
> easily.

All true, but some make it easier to obfuscate.

C/C++ has the bad taste to want to be what the Germans
disparagingly term an "eierlegende Wollmilchsau", i.e.
an egg-laying wool-milk-sow.


>> Yes, it is entirely possible to write code that is clear,
>> simple, and easy to read. Not everybody achieves that.
>>
>
> Not everybody is a good programmer.  Not even all professional
> programmers are good programmers.
>
> It is fair to say that as it is a bigger language, it takes longer to be
> a good C++ programmer than a good C programmer.

Big != good. In fact, big language == bad.

I strongly prefer a simple language plus extensive libraries
embodying the right abstractions for the task at hand.

No one language will ever be able to do that for
all application domains.


> It is perhaps also fair
> to say that for the same reason, a bad C++ programmer can make a bigger
> mess than a bad C programmer.  But I have seen enough bad C code to know
> that a small language does not mean clearer or better code.

The same is true of any language, of course - especially
home-grown domain specific languages!



>>>>> So C++11 allows some fancy tricks like, but they should not be used
>>>>> until C++14 and generalised constexpr functions.  (I can't remember
>>>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>>>
>>>> And that, in a nutshell, is one recurring problem with C/C++
>>>
>>> If you want to use modern features, use a modern compiler.  I don't
>>> track all features and all versions of gcc in my head - but I know how
>>> to look it up.  It is not hard.
>>
>> The real nasty is that frequently C/C++ compilers
>> implement /a/ subset of a standard, where the subset
>> depends on what is convenient and what the compiler
>> writers understand.
>
> There is no "real nasty" about it.  It usually takes time between a
> standard being published, and compilers having full support for it.  If
> you want to write code that requires C++14, you can look at the
> documentation for your compiler and version to see if it supports it.
> And you give the compiler a command-line flag to match.  If you want to
> compile C++14 code with gcc, you write "g++ -std=c++14" or "g++
> -std=gnu++14" (for gcc extensions).  If the compiler does not support
> it, it tells you.  If you want experimental partial support for newer
> features, look up the flags to enable that.
>
> Both C and C++ standards go to extraordinary lengths to support backward
> compatibility, so that old code still works with newer compilers and
> newer standards.

Indeed. That's _necessary_, a strength and also a weakness.

Sometimes it is better to start again, keeping only the
elegant, and discarding the cruft.


>> ISTR a triumphant announcement that the first complete
>> C++ compiler was available, 4/5/6 years after the
>> standard was published.
>
> The first C++ compiler (Cfront from 1983) was available long before the
> first C++ standard was published (C++98, in 1998).  The first unofficial
> sort-of-standard was the 1985 book "The C++ Programming Language".  gcc
> supported C++ from 1987.
>
> In the early days of C++, it took a while for new features to be
> properly implemented on a range of compilers.  They are a lot better
> now.  The serious C++ compilers (gcc, clang, MSVC, EDG front end) all
> have full support for C++14.  gcc and clang have full support for C++17
> (which was finished a few months ago, but I think is still not
> officially published).

My apologies; I'm sure you are right.

My recollection is from ~2003, so it would have been
one of the late 90s languages. I wish I had kept a
copy of the announcement. I didn't dream I would still
be remembering it.

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


#481593

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-16 11:18 +0200
Message-ID<os1thb$536$1@dont-email.me>
In reply to#480596
On 06/10/17 18:44, Tom Gardner wrote:
> On 06/10/17 15:32, David Brown wrote:
>> On 06/10/17 14:55, Tom Gardner wrote:
>>> On 06/10/17 13:24, David Brown wrote:
>>>> On 06/10/17 12:47, Tom Gardner wrote:
>>>>> On 06/10/17 08:36, David Brown wrote:
>>>>>> and while
>>>>>> everything works correctly (it's easy to check), your code review
>>>>>> folks
>>>>>> are sticking hot pokers in their eyes to avoid looking at it.
>>>>>
>>>>> And that, in a nutshell, is one problem with C/C++
>>>>>
>>>>
>>>> There are two solutions to it.  One is that when a feature appears
>>>> useful but cumbersome, C++ evolves to make it simpler.  Examples
>>>> include
>>>> recursive template programming (replaced by variadic templates and
>>>> generalised constexpr functions), the safe boolean idiom (replaced by
>>>> explicit conversion operators), and "enable_if" templates (replaced by
>>>> concepts).
>>>>
>>>> (If those terms don't mean anything to you, you should question how
>>>> valid your opinions on C++ are without knowledge of the modern
>>>> language.)
>>>>
>>>> The other solution is to realise that you can program in C++ without
>>>> understanding all the fiddly and complex bits - you can leave those to
>>>> the folks writing libraries.  This is the same in most programming
>>>> languages.
>>>
>>> Just so.
>>>
>>> But that doesn't affect the point; C++ descends into being
>>> a write-only state more easily than other equally powerful
>>> languages.
>>
>> 1. I know of no languages with the breadth of features, the breadth of
>> programming styles, and the breadth of target application types, than
>> C++.  I don't know what you could compare it to here.
> 
> No single language, of course - but I regard that as
> unimportant. 

OK, so your point about "equally powerful languages" is a non-starter?

It can often make sense to build different parts of a large system using
different programming languages - one size does not fit all.  So I can
agree that the existence of a single language covering such as range as
C++ is not essential, but it can certainly be convenient.

> Similarly I would have no interest in a
> hammer that also extruded glue.
> 

Think of C++ as a toolbox, rather than a hammer-and-glue combo.  You
don't have to use all the tools in the toolbox, and you certainly don't
have to use them all in the same project.  But most of them will be
useful to some people at some time.

> C/C++ has the bad taste to aim at being what the Germans
> disparagingly term an "eierlegende Wollmilchsau", i.e.
> an egg-laying wool-milk-sow.
> 

There is no language "C/C++".  When you write that, it screams "I don't
know much about C /or/ C++".  There is nothing wrong with ignorance -
but there is a lot wrong with arguing from a position of ignorance.

The scope for C is far smaller than that for C++, especially if you
consider where C /should/ be used rather than were C /is/ used.

> 
>> 2. All languages are write only when you are not familiar with them, or
>> at least with similar languages.
>>
>> 3. A skilled obfuscater can write write-only code in any language quite
>> easily.
> 
> All true, but some make it easier to obfuscate.

Yes - but neither C nor C++ is such a language.

C++ lets you write some pretty complicated stuff, and some areas of it
are definitely advanced and only accessible to experts.  That does not
mean the code is obfuscated - on the contrary, the code is usually
written as clearly as possible.  It just means it is /hard/.  A key
point about C++ that is different from almost any other language, is
that much of the "language" is formed by the /library/, and that the
library should be written in C++.  Many other languages are designed
with a large standard library, but the /implementation/ of these
libraries is usually done in C for speed.

So in Python or PHP, data structures like hashmaps (or dictionaries, or
arrays, or whatever you like to call them) are part of the /language/,
with the actual implementation in C.  These languages don't need a way
to make such structures efficiently.  In C++, the language needs the
scaffolding in order to design such structures efficiently in C++.  That
means templates, SFINAE, move constructors, and all the other
"difficult" parts of the language.  That does not mean that ordinary
users are expected to use all these low-level parts - they can just use
a "std::map" when they need it, and leave the library implementation up
to the library experts.

> 
> C/C++ has the bad taste to want to be what the Germans
> disparagingly term an "eierlegende Wollmilchsau", i.e.
> an egg-laying wool-milk-sow.
> 
> 
>>> Yes, it is entirely possible to write code that is clear,
>>> simple, and easy to read. Not everybody achieves that.
>>>
>>
>> Not everybody is a good programmer.  Not even all professional
>> programmers are good programmers.
>>
>> It is fair to say that as it is a bigger language, it takes longer to be
>> a good C++ programmer than a good C programmer.
> 
> Big != good. In fact, big language == bad.

Big is good for some things.  Small is good for some things.

> 
> I strongly prefer a simple language plus extensive libraries
> embodying the right abstractions for the task at hand.

The C++ core language is not actually /that/ big.  It is certainly
bigger than the C language, but it is not huge.  A great deal of C++ is
the libraries, rather than the core language.

> 
> No one language will ever be able to do that for
> all application domains.
> 
> 
>> It is perhaps also fair
>> to say that for the same reason, a bad C++ programmer can make a bigger
>> mess than a bad C programmer.  But I have seen enough bad C code to know
>> that a small language does not mean clearer or better code.
> 
> The same is true of any language, of course - especially
> home-grown domain specific languages!
> 
> 
> 
>>>>>> So C++11 allows some fancy tricks like, but they should not be used
>>>>>> until C++14 and generalised constexpr functions.  (I can't remember
>>>>>> off-hand if gcc 5.3 supports that - I /think/ it does.)
>>>>>
>>>>> And that, in a nutshell, is one recurring problem with C/C++
>>>>
>>>> If you want to use modern features, use a modern compiler.  I don't
>>>> track all features and all versions of gcc in my head - but I know how
>>>> to look it up.  It is not hard.
>>>
>>> The real nasty is that frequently C/C++ compilers
>>> implement /a/ subset of a standard, where the subset
>>> depends on what is convenient and what the compiler
>>> writers understand.
>>
>> There is no "real nasty" about it.  It usually takes time between a
>> standard being published, and compilers having full support for it.  If
>> you want to write code that requires C++14, you can look at the
>> documentation for your compiler and version to see if it supports it.
>> And you give the compiler a command-line flag to match.  If you want to
>> compile C++14 code with gcc, you write "g++ -std=c++14" or "g++
>> -std=gnu++14" (for gcc extensions).  If the compiler does not support
>> it, it tells you.  If you want experimental partial support for newer
>> features, look up the flags to enable that.
>>
>> Both C and C++ standards go to extraordinary lengths to support backward
>> compatibility, so that old code still works with newer compilers and
>> newer standards.
> 
> Indeed. That's _necessary_, a strength and also a weakness.
> 
> Sometimes it is better to start again, keeping only the
> elegant, and discarding the cruft.

Agreed.  C++ does that a bit (such as re-using "auto" for a completely
different purpose in C++11, and dropping the "register" keyword).  C
almost never makes changes that breaks old code - that is one of the
major features of it as a language.

Discarding stuff and starting again can be a good thing - but you only
need to look at the mass of Python 2 code that is incompatible with
Python 3 to see that it comes at a very high price.

C++ tries to keep a middle ground.  It only breaks things that either
were very rarely used (like pre-C++11 "auto"), or were often wrong in
the first place.  But that also means that there can be many ways to do
the same thing in C++ - the "new" way and the "old" way, since the new
ways have to be in addition to the old ways.

> 
> 
>>> ISTR a triumphant announcement that the first complete
>>> C++ compiler was available, 4/5/6 years after the
>>> standard was published.
>>
>> The first C++ compiler (Cfront from 1983) was available long before the
>> first C++ standard was published (C++98, in 1998).  The first unofficial
>> sort-of-standard was the 1985 book "The C++ Programming Language".  gcc
>> supported C++ from 1987.
>>
>> In the early days of C++, it took a while for new features to be
>> properly implemented on a range of compilers.  They are a lot better
>> now.  The serious C++ compilers (gcc, clang, MSVC, EDG front end) all
>> have full support for C++14.  gcc and clang have full support for C++17
>> (which was finished a few months ago, but I think is still not
>> officially published).
> 
> My apologies; I'm sure you are right.
> 
> My recollection is from ~2003, so it would have been
> one of the late 90s languages. I wish I had kept a
> copy of the announcement. I didn't dream I would still
> be remembering it.

It could well be that the first full C++98 compilers came out years
after that standard was published.  Certainly it took many years before
C compilers implemented most of C99.  It may also be that the
announcement you saw was for "the first version of the XXX compiler to
support C++98", rather than the first such C++ compiler in general.  And
there is also the complicated question of /full/ support for a standard
- most compilers have oddities where they don't quite support everything
in a standard, but usually such corner cases are irrelevant in practice.

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


#480911

FromJasen Betts <jasen@xnet.co.nz>
Date2017-10-09 07:58 +0000
Message-ID<orfa83$7do$1@gonzo.alcatraz>
In reply to#480568
On 2017-10-06, Tom Gardner <spamjunk@blueyonder.co.uk> wrote:

> The real nasty is that frequently C/C++ compilers
> implement /a/ subset of a standard, where the subset
> depends on what is convenient and what the compiler
> writers understand.
>
> ISTR a triumphant announcement that the first complete
> C++ compiler was available, 4/5/6 years after the
> standard was published.

Around 2007 I was discovering that while GCC was a good win32 C99
compiler, there was no C99 support in MSVCRT.DLL, so C99 language
features worked, but C99 library features did not.

-- 
This email has not been checked by half-arsed antivirus software 

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


#481594

FromDavid Brown <david.brown@hesbynett.no>
Date2017-10-16 11:23 +0200
Message-ID<os1tr1$784$1@dont-email.me>
In reply to#480911
On 09/10/17 09:58, Jasen Betts wrote:
> On 2017-10-06, Tom Gardner <spamjunk@blueyonder.co.uk> wrote:
> 
>> The real nasty is that frequently C/C++ compilers
>> implement /a/ subset of a standard, where the subset
>> depends on what is convenient and what the compiler
>> writers understand.
>>
>> ISTR a triumphant announcement that the first complete
>> C++ compiler was available, 4/5/6 years after the
>> standard was published.
> 
> Around 2007 I was discovering that while GCC was a good win32 C99
> compiler, there was no C99 support in MSVCRT.DLL, so C99 language
> features worked, but C99 library features did not.
> 

MSVC has famously had terrible C99 support.  It has supported some C99
language features - primarily those that overlap with new features in
C++.  But MSVC developers have always regarded C as a dead language
supported "as is" for old code, rather than with new features for new
code.  And thus the standard C runtime library from MSVC has had no C99
support other than as needed for C++.

I believe that current versions of MSVC are better, with more support in
the libraries and with a move to clang for the C front end (clang has
full C99 and C11 support).  But I am not an MSVC user, so I don't have
details.

When using gcc on Windows, you can use libraries other than MSVC's dll.
 Not only will you get better C99 support, you will get significantly
faster code - using a DLL for basic library support (rather than a
statically linked library, or at least a decent linking system like on
*nix systems) is going to give you massive overheads.

[toc] | [prev] | [standalone]


Back to top | Article view | sci.electronics.design


csiph-web