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

The differences tend not to be all that great provided that the back end code generator has a reasonably good optimiser. You can find some bad older compilers if you look hard enough but most modern optimisers these days can turn sensible code into tight assembler.

Attempting to micromanage things in a HLL sometimes confuses optimisers.

The snag may come at link time where with some languages it is possible to inadvertently use a feature that imports the kitchen sink and some.

--
Regards, 
Martin Brown
Reply to
Martin Brown
Loading thread data ...

Hiding differences in the on-chip peripherals is a good use for a class library. Most of my C++ stuff is "C with classes and a few templates" rather than lambdas, metaprogramming, and so on. I've been using the standard library facilities more and more as I go along, especially std::unique_ptr and std::shared_ptr.

One reason that C++ code reuse hasn't lived up to its billing is that different people's libraries have different and incompatible assumptions. For prototype code, I often use Numerical Recipes 2nd Ed C code (I made shared libraries (.so and .dll) out of it long ago and still use them.) It has its ugly aspects, especially in using file static variables to pass things invisibly between functions, but the C bindings are easy to use.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

LOL! Pot, kettle...

--

Rick C
Reply to
rickman

What's wrong with Forth?

--

Rick C
Reply to
rickman

WriteOnly Habit Bad It Is

Made sense on very early minis for instrument control - although I can recall a real nightmare product that tried to use Forth and failed.

--
Regards, 
Martin Brown
Reply to
Martin Brown

s/Forth/C++/ also makes equal sense :(

Reply to
Tom Gardner

I had a Forth interpreter for the 128K Macintosh. Fun, but integer-only arithmetic made it a toy.

I like stack-oriented RPN though--I use an HP41CV a few times a week.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC 
Optics, Electro-optics, Photonics, Analog Electronics 

160 North State Road #203 
Briarcliff Manor NY 10510 

hobbs at electrooptical dot net 
http://electrooptical.net
Reply to
Phil Hobbs

My go-to calculator on my linux box (for calcs where a spreadsheet wouldn't be easier) is an HP15C emulator. I also have two HP32Ss, and a Sinclair Scientific.

I never could get the hang of those half-RPN calculators, where sin(60+30) is entered as 60 + 30 = sin.

It is also fun to annoy people by claiming that PostScript is Forth with a library for imaging. I've only ever written one program in Postscript, but I admire the people that draw Smith Charts in the printer :)

Reply to
Tom Gardner

4th ?? if honk then
Reply to
whit3rd

In volume, the difference between the small (i.e. QFN32) 16K, 32K, and

64K Atmel M0s is $.02 and $.03.
Reply to
krw

It is a write-only language, good for calculators etc, but already too difficult in Open Boot.

--

-TV
Reply to
Tauno Voipio

Nice! I expect that they are all the same chip inside anyway?

By the way that $1 STM32F301 I referenced is a fairly full featured part with a M4 core, DSP, FPU. It is quite a nice little analog toolkit, a bit like the ADUC702x parts were.

Of course there are M0's for a fraction of that $1 now.

--

John Devereux
Reply to
John Devereux

One good thing about Forth is that it forces you to learn how to give descriptive names to functions ("words" in Forth). That skill is highly useful in all languages--if you can't find a short, descriptive name, the function needs refactoring.

Cheers

Phil Hobbs

Reply to
pcdhobbs

Yes, I'm told the only difference is test. The 16K version also only has 4K SRAM. The others are 8K, IIRC.

Still impressive for an M4. The M7s we're using are a couple of times that.

Reply to
krw

That is certainly the case for some Atmel devices. It all depends on the quantities they make - if there is enough call for the smaller memory sizes, they will make production runs that really only have the smaller memories and save a few cents on the dies. But it has to be quite a sizeable order to make it worth the effort.

I remember long ago working with COP8 microcontrollers with OTP memory, where the 32K devices were cheapest, the 16K versions cost a little more, and the 8K versions cost even more. It was partly a matter of the quantities made and sold, but also because the smaller memory parts were the same die as the full 32K version, but there was an extra step in production to program the extra memory with zeros!

Reply to
David Brown

...

A lot of folks miss the fact that the Arduino environment is C++ (not C). This is likely intentional to avoid scaring newbies. The following exhibit is just one example:

formatting link

How you use C++ will determine whether the end result is slim or bloated.

Warren

Reply to
Warren

The Arduino sketch goes through a preprocessor that converts it to C++ and then onto the compiler and linker.

You can write C++ classes in the sketch and use them in your code - they go straight through the preprocessor to the compiler. In fact most (all?) the Arduino libraries are C++. Just look at the usage.

Reply to
Dennis

There is no "language conversion". All C and C++ programs go through the preprocessor. Arduino may however, do some additional scanning to determine which libraries to link with at the link step. Otherwise, the process is almost native IIRC.

That's what I'm sayin'. :)

In fact, you can't do straight C in Arduino, unless you use the extern "C" { } stuff. Structure initialization rules are slightly different between C and C++, for example. I'm not sure if the structure initialization changes to C conventions within the extern "C" { } group-- I've never had reason to try it.

Warren

Reply to
Warren

I would think that order would have to have seven or eight zeros to offset the cost of a new design. Six certainly isn't enough (that's the quantity we received the quotes for).

That seems silly. Just ignore the bits or blow a fuse to disable high memory. Or, just blow some random locations. ;-)

Reply to
krw

As a Luddite who never felt the need to move on from good old K&R C, and someone who's already ordered an Arduino for an embedded app, I admit to feeling slightly perturbed by your above remarks.

Reply to
Cursitor Doom

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.