Forums

"modern" C++ and microcontrollers: match made in heaven?

Started by bitrex January 12, 2017
"Conventional wisdom" says that one should always stick to languages
like C and ASM when writing code for "resource constrained" processors 
like the AVR and el cheapo ARMs.

My somewhat-educated opinion is that it's not true. At least, not anymore.

Instead of just bloating the code, the constructs available in the 
recent variants of C++ compilers (C++11 and later) allow you to unleash 
the full fury of these little processors.

"Modern" C++ offers high levels of abstraction and straightforward 
resource management, while remaining a performance beast.
On Thu, 12 Jan 2017 12:03:54 -0500, bitrex
<bitrex@de.lete.earthlink.net> wrote:

>"Conventional wisdom" says that one should always stick to languages >like C and ASM when writing code for "resource constrained" processors >like the AVR and el cheapo ARMs. > >My somewhat-educated opinion is that it's not true. At least, not anymore. > >Instead of just bloating the code, the constructs available in the >recent variants of C++ compilers (C++11 and later) allow you to unleash >the full fury of these little processors. > >"Modern" C++ offers high levels of abstraction and straightforward >resource management, while remaining a performance beast.
Well, if you admire abstraction. In an embedded application, I'd rather have everything in plain sight. -- John Larkin Highland Technology, Inc lunatic fringe electronics
On Thu, 12 Jan 2017 09:25:26 -0800, John Larkin
<jjlarkin@highlandtechnology.com> wrote:

>On Thu, 12 Jan 2017 12:03:54 -0500, bitrex ><bitrex@de.lete.earthlink.net> wrote: > >>"Conventional wisdom" says that one should always stick to languages >>like C and ASM when writing code for "resource constrained" processors >>like the AVR and el cheapo ARMs. >> >>My somewhat-educated opinion is that it's not true. At least, not anymore. >> >>Instead of just bloating the code, the constructs available in the >>recent variants of C++ compilers (C++11 and later) allow you to unleash >>the full fury of these little processors. >> >>"Modern" C++ offers high levels of abstraction and straightforward >>resource management, while remaining a performance beast. > >Well, if you admire abstraction. In an embedded application, I'd >rather have everything in plain sight.
I have to wonder... is bitrex as unskilled at programming as he is at small-signal AC analysis ?>:-} ...Jim Thompson -- | James E.Thompson | mens | | Analog Innovations | et | | Analog/Mixed-Signal ASIC's and Discrete Systems | manus | | STV, Queen Creek, AZ 85142 Skype: skypeanalog | | | Voice:(480)460-2350 Fax: Available upon request | Brass Rat | | E-mail Icon at http://www.analog-innovations.com | 1962 |
On Thu, 12 Jan 2017 10:29:28 -0700, Jim Thompson
<To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote:

>On Thu, 12 Jan 2017 09:25:26 -0800, John Larkin ><jjlarkin@highlandtechnology.com> wrote: > >>On Thu, 12 Jan 2017 12:03:54 -0500, bitrex >><bitrex@de.lete.earthlink.net> wrote: >> >>>"Conventional wisdom" says that one should always stick to languages >>>like C and ASM when writing code for "resource constrained" processors >>>like the AVR and el cheapo ARMs. >>> >>>My somewhat-educated opinion is that it's not true. At least, not anymore. >>> >>>Instead of just bloating the code, the constructs available in the >>>recent variants of C++ compilers (C++11 and later) allow you to unleash >>>the full fury of these little processors. >>> >>>"Modern" C++ offers high levels of abstraction and straightforward >>>resource management, while remaining a performance beast. >> >>Well, if you admire abstraction. In an embedded application, I'd >>rather have everything in plain sight. > >I have to wonder... is bitrex as unskilled at programming as he is at >small-signal AC analysis ?>:-} > > ...Jim Thompson
Jim, stop being a jerk. -- John Larkin Highland Technology, Inc picosecond timing precision measurement jlarkin att highlandtechnology dott com http://www.highlandtechnology.com
On Thu, 12 Jan 2017 10:01:48 -0800, John Larkin
<jjlarkinxyxy@highlandtechnology.com> wrote:

>On Thu, 12 Jan 2017 10:29:28 -0700, Jim Thompson ><To-Email-Use-The-Envelope-Icon@On-My-Web-Site.com> wrote: > >>On Thu, 12 Jan 2017 09:25:26 -0800, John Larkin >><jjlarkin@highlandtechnology.com> wrote: >> >>>On Thu, 12 Jan 2017 12:03:54 -0500, bitrex >>><bitrex@de.lete.earthlink.net> wrote: >>> >>>>"Conventional wisdom" says that one should always stick to languages >>>>like C and ASM when writing code for "resource constrained" processors >>>>like the AVR and el cheapo ARMs. >>>> >>>>My somewhat-educated opinion is that it's not true. At least, not anymore. >>>> >>>>Instead of just bloating the code, the constructs available in the >>>>recent variants of C++ compilers (C++11 and later) allow you to unleash >>>>the full fury of these little processors. >>>> >>>>"Modern" C++ offers high levels of abstraction and straightforward >>>>resource management, while remaining a performance beast. >>> >>>Well, if you admire abstraction. In an embedded application, I'd >>>rather have everything in plain sight. >> >>I have to wonder... is bitrex as unskilled at programming as he is at >>small-signal AC analysis ?>:-} >> >> ...Jim Thompson > >Jim, stop being a jerk.
You apparently haven't been following the "Interesting negative capacitance circuit" thread ?? ...Jim Thompson -- | James E.Thompson | mens | | Analog Innovations | et | | Analog/Mixed-Signal ASIC's and Discrete Systems | manus | | STV, Queen Creek, AZ 85142 Skype: skypeanalog | | | Voice:(480)460-2350 Fax: Available upon request | Brass Rat | | E-mail Icon at http://www.analog-innovations.com | 1962 |
On Thu, 12 Jan 2017 10:29:28 -0700, Jim Thompson wrote:

> On Thu, 12 Jan 2017 09:25:26 -0800, John Larkin > <jjlarkin@highlandtechnology.com> wrote: > >>On Thu, 12 Jan 2017 12:03:54 -0500, bitrex >><bitrex@de.lete.earthlink.net> wrote: >> >>>"Conventional wisdom" says that one should always stick to languages >>>like C and ASM when writing code for "resource constrained" processors >>>like the AVR and el cheapo ARMs. >>> >>>My somewhat-educated opinion is that it's not true. At least, not >>>anymore. >>> >>>Instead of just bloating the code, the constructs available in the >>>recent variants of C++ compilers (C++11 and later) allow you to unleash >>>the full fury of these little processors. >>> >>>"Modern" C++ offers high levels of abstraction and straightforward >>>resource management, while remaining a performance beast. >> >>Well, if you admire abstraction. In an embedded application, I'd rather >>have everything in plain sight. > > I have to wonder... is bitrex as unskilled at programming as he is at > small-signal AC analysis ?>:-}
His prose is a bit overblown, but if what I've read recently is any indication then yes, C++ is getting slim and trim enough at least for 8K/1K flash/ram processors. A single application that small wouldn't drive me to using C++, but if I had a product line with a lot of code that I wanted to re-use I'd certainly consider C++ in such a situation. -- Tim Wescott Control systems, embedded software and circuit design I'm looking for work! See my website if you're interested http://www.wescottdesign.com
On Thu, 12 Jan 2017 12:03:54 -0500, bitrex wrote:

> "Conventional wisdom" says that one should always stick to languages > like C and ASM when writing code for "resource constrained" processors > like the AVR and el cheapo ARMs. > > My somewhat-educated opinion is that it's not true. At least, not > anymore. > > Instead of just bloating the code, the constructs available in the > recent variants of C++ compilers (C++11 and later) allow you to unleash > the full fury of these little processors. > > "Modern" C++ offers high levels of abstraction and straightforward > resource management, while remaining a performance beast.
It depends. I just don't think you need C++ in a really small processor -- C++ is a good tool to manage large, complicated programs; by definition anything that fits into 4K or 8K of flash isn't large. Moreover, C++ makes it really easy to add functionality, and functionality means more flash used. So you'd be building a slippery slope into your development process. Having said that, if you had a lot of code that you wanted to easily reuse across products, then C++ on small processors might make sense. -- Tim Wescott Control systems, embedded software and circuit design I'm looking for work! See my website if you're interested http://www.wescottdesign.com
On 12/01/17 18:09, Tim Wescott wrote:
> On Thu, 12 Jan 2017 10:29:28 -0700, Jim Thompson wrote: > >> On Thu, 12 Jan 2017 09:25:26 -0800, John Larkin >> <jjlarkin@highlandtechnology.com> wrote: >> >>> On Thu, 12 Jan 2017 12:03:54 -0500, bitrex >>> <bitrex@de.lete.earthlink.net> wrote: >>> >>>> "Conventional wisdom" says that one should always stick to languages >>>> like C and ASM when writing code for "resource constrained" processors >>>> like the AVR and el cheapo ARMs. >>>> >>>> My somewhat-educated opinion is that it's not true. At least, not >>>> anymore. >>>> >>>> Instead of just bloating the code, the constructs available in the >>>> recent variants of C++ compilers (C++11 and later) allow you to unleash >>>> the full fury of these little processors. >>>> >>>> "Modern" C++ offers high levels of abstraction and straightforward >>>> resource management, while remaining a performance beast. >>> >>> Well, if you admire abstraction. In an embedded application, I'd rather >>> have everything in plain sight. >> >> I have to wonder... is bitrex as unskilled at programming as he is at >> small-signal AC analysis ?>:-} > > His prose is a bit overblown, but if what I've read recently is any > indication then yes, C++ is getting slim and trim enough at least for > 8K/1K flash/ram processors. > > A single application that small wouldn't drive me to using C++, but if I > had a product line with a lot of code that I wanted to re-use I'd > certainly consider C++ in such a situation.
For such a small MCU application, I'd have thought that C++ wouldn't offer sufficient advantages over C.
On 01/12/2017 01:11 PM, Tim Wescott wrote:
> On Thu, 12 Jan 2017 12:03:54 -0500, bitrex wrote: > >> "Conventional wisdom" says that one should always stick to languages >> like C and ASM when writing code for "resource constrained" processors >> like the AVR and el cheapo ARMs. >> >> My somewhat-educated opinion is that it's not true. At least, not >> anymore. >> >> Instead of just bloating the code, the constructs available in the >> recent variants of C++ compilers (C++11 and later) allow you to unleash >> the full fury of these little processors. >> >> "Modern" C++ offers high levels of abstraction and straightforward >> resource management, while remaining a performance beast. > > It depends. I just don't think you need C++ in a really small processor > -- C++ is a good tool to manage large, complicated programs; by > definition anything that fits into 4K or 8K of flash isn't large. > > Moreover, C++ makes it really easy to add functionality, and > functionality means more flash used. So you'd be building a slippery > slope into your development process. > > Having said that, if you had a lot of code that you wanted to easily > reuse across products, then C++ on small processors might make sense. >
The "Tiny" series of AVRs have a max of 8k or so, but I think it's getting to be that the only advantage of those little devices with no hardware multiply, etc. is in applications that require ultra-low power. A MegaAVR usually has like 32k program memory, and even the dumpiest $2 Cortexs often have 128k. GCC is pretty tight, you can fit a lot of stuff in there!
On 01/12/2017 12:25 PM, John Larkin wrote:
> On Thu, 12 Jan 2017 12:03:54 -0500, bitrex > <bitrex@de.lete.earthlink.net> wrote: > >> "Conventional wisdom" says that one should always stick to languages >> like C and ASM when writing code for "resource constrained" processors >> like the AVR and el cheapo ARMs. >> >> My somewhat-educated opinion is that it's not true. At least, not anymore. >> >> Instead of just bloating the code, the constructs available in the >> recent variants of C++ compilers (C++11 and later) allow you to unleash >> the full fury of these little processors. >> >> "Modern" C++ offers high levels of abstraction and straightforward >> resource management, while remaining a performance beast. > > Well, if you admire abstraction. In an embedded application, I'd > rather have everything in plain sight.
Enter test-driven development: if the code that forms the basis of your abstraction passes all the required unit tests, and can be verified "correct" from the perspective of your chosen static analysis tools, then it's unlikely to be the source of your problems higher up the chain. Of course I'm not talking about life-critical applications here, I'm sure they have an entirely different set of standards. (which Toyota's engineers for the 2000-something Camry apparently didn't care about.) Ever taken a look at the codebase for the humble std::cout? Jeez!