Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #30504
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.arch.embedded |
| Subject | Re: C++, Ada, ... |
| Date | 2021-04-19 08:52 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <s5j9bk$ced$1@dont-email.me> (permalink) |
| References | (4 earlier) <ie34olFmda9U1@mid.individual.net> <s5hq48$k2e$1@dont-email.me> <WU_eI.237389$KHwf.63256@fx25.ams4> <s5i441$tro$1@dont-email.me> <Kd2fI.273342$zV01.166134@fx49.ams4> |
On 19/04/2021 00:17, Tom Gardner wrote: > On 18/04/21 21:17, David Brown wrote: >> On 18/04/2021 20:30, Tom Gardner wrote: >>> On 18/04/21 18:26, David Brown wrote: >>>> C++ has got a lot stronger at compile-time work in recent versions. >>>> Not >>>> only have templates got more powerful, but we've got "concepts" (named >>>> sets of features or requirements for types), constexpr functions (that >>>> can be evaluated at compile time or runtime), consteval functions (that >>>> must be evaluated at compile time), constinit data (that must have >>>> compile-time constant initialisers), etc. And constants determined at >>>> compile-time are not restricted to scaler or simple types. >>> >>> Sounds wordy ;) >> >> Have you looked at the C++ standards documents? There are more than a >> few words there! > > No. I value my sanity. I have looked at it, and come back as sane as ever (apart from the pencils up my nose and underpants on my head). But I've worked up to it through many versions of the C standards. More seriously, if I need to look up any details of C or C++, I find <https://en.cppreference.com/w/> vastly more user-friendly. > > >> I'm not suggesting C++ is a perfect language - not by a long way. It >> has plenty of ugliness, and in this thread we've covered several points >> where Ada can do something neater and clearer than you can do it in C++. >> >> But it's a good thing that it has more ways for handling things at >> compile time. In many of my C projects, I have had Python code for >> pre-processing, for computing tables, and that kind of thing. With >> modern C++, these are no longer needed. > > The useful question is not whether something is good, > but whether there are better alternatives. "Better", > of course, can include /anything/ relevant! > Yes - and "better" is usually highly subjective. In the case of compile-time calculations, modern C++ is certainly better than older C++ versions or C (or, AFAIK, Ada). It can't do everything that I might do with external Python scripts - it can't do code generation, or make tables that depend on multiple source files, or make CRC checks for the final binary. But it can do some things that previously required external scripts, and that's nice. > > >> An odd thing about the compile-time calculation features of C++ is that >> they came about partly by accident, or unforeseen side-effects. Someone >> discovered that templates with integer parameters could be used to do >> quite a lot of compile-time calculations. The code was /really/ ugly, >> slow to compile, limited in scope. But people were finding use for it. >> So the motivation for "constexpr" was that programmers were already >> doing compile-time calculations, and so it was best to let them do it in >> a nicer way. > > Infamously, getting a valid C++ program that cause the > compiler to generate the sequence of prime numbers during > compilation came as an unpleasant /surprise/ to the C++ > standards committee. I don't believe that the surprise was "unpleasant" - it's just something they hadn't considered. (I'm not even sure of that either - my feeling is that this is an urban myth, or at least a story exaggerated in the regular retelling.) > > The code is short; whether it is ugly is a matter of taste! > https://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming#History_of_TMP > Template-based calculations were certainly very convoluted - they needed a functional programming style structure but with much more awkward syntax (and at the height of their "popularity", horrendous compiler error messages when you made a mistake - that too has improved greatly). And that is why constexpr (especially in latest versions) is so much better. Template-based calculations are a bit like trying to do calculations and data structures in LaTeX. It is all possible, but it doesn't roll off the tongue very easily. (I wonder if anyone else understands the pencil and underpants reference. I am sure Tom does.)
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C++, Ada, ... pozz <pozzugno@gmail.com> - 2021-04-17 17:48 +0200
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-17 18:45 +0200
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-17 19:55 +0100
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-18 12:53 +0200
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-18 18:48 +0300
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-18 18:59 +0200
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-19 13:51 +0300
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 14:22 +0200
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-19 19:16 +0300
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 22:19 +0200
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-20 01:03 +0300
Re: C++, Ada, ... Richard Damon <Richard@Damon-Family.org> - 2021-04-19 18:09 -0400
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-20 06:58 +0200
Re: C++, Ada, ... Paul Rubin <no.email@nospam.invalid> - 2021-04-19 23:18 -0700
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-20 09:36 +0200
Re: C++, Ada, ... Paul Rubin <no.email@nospam.invalid> - 2021-04-19 12:20 -0700
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-20 00:26 +0300
Re: C++, Ada, ... Paul Rubin <no.email@nospam.invalid> - 2021-04-19 16:01 -0700
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-20 10:47 +0300
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-19 23:30 +0100
Re: C++, Ada, ... Clifford Heath <no.spam@please.net> - 2021-04-18 08:29 +1000
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-18 10:39 +0300
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-18 14:59 +0200
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-18 19:23 +0300
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-18 19:26 +0200
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-18 19:29 +0100
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-18 22:23 +0200
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-18 23:09 +0100
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 08:56 +0200
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-19 14:04 +0300
Re: C++, Ada, ... Dimiter_Popoff <dp@tgi-sci.com> - 2021-04-19 15:16 +0300
Re: C++, Ada, ... Paul Rubin <no.email@nospam.invalid> - 2021-04-19 12:47 -0700
Re: C++, Ada, ... Niklas Holsti <niklas.holsti@tidorum.invalid> - 2021-04-20 00:37 +0300
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-20 07:50 +0200
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 14:26 +0200
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-18 19:30 +0100
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-18 22:17 +0200
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-18 23:17 +0100
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 08:52 +0200
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-19 10:08 +0100
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 12:15 +0200
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-19 12:00 +0100
Re: C++, Ada, ... Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2021-04-19 16:15 +0300
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 15:43 +0200
Re: C++, Ada, ... pozz <pozzugno@gmail.com> - 2021-04-19 18:38 +0200
Re: C++, Ada, ... Paul Rubin <no.email@nospam.invalid> - 2021-04-19 10:48 -0700
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-19 19:33 +0100
Re: C++, Ada, ... Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2021-04-20 15:09 +0300
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-20 15:29 +0100
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-19 22:48 +0200
Re: C++, Ada, ... pozz <pozzugno@gmail.com> - 2021-04-19 23:17 +0200
Re: C++, Ada, ... Paul Rubin <no.email@nospam.invalid> - 2021-04-19 15:55 -0700
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-20 08:21 +0200
Re: C++, Ada, ... David Brown <david.brown@hesbynett.no> - 2021-04-20 08:20 +0200
Re: C++, Ada, ... Dave Nadler <drn@nadler.com> - 2021-04-17 21:07 -0400
Re: C++, Ada, ... Don Y <blockedofcourse@foo.invalid> - 2021-04-17 18:53 -0700
Re: C++, Ada, ... Tom Gardner <spamjunk@blueyonder.co.uk> - 2021-04-18 09:42 +0100
Re: C++, Ada, ... dalai lamah <antonio12358@hotmail.com> - 2021-04-18 14:39 +0200
csiph-web