version=D_16

Mike via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 13 13:37:29 PDT 2017


On Monday, 10 July 2017 at 21:30:44 UTC, Walter Bright wrote:

> You can't use RTTI or Exceptions, for example. Those generate 
> bloat even if they are not used - a compiler switch is typical 
> to disable them. It's not true that C++ is "pay only for what 
> you use".
>
> If the C++ usage is "C with member functions", then yes, it'll 
> work and be useful.

I use C++ for microcontrollers all the time and I prefer to use 
exceptions and RTTI for most of my applications. There is a small 
amount of bloat when using RTTI and exceptions, but the linker is 
able to strip a large amount of it out, so the cost is minimal 
and opt-in.  I don't see why D couldn't do the same; it just 
needs to generate code in a way that allows the linker to 
identify dead code.

The only binary size problems I've encountered using C++ is using 
iostream and formatted IO.  Those seem to generate the most 
bloat.  But if you avoid iostream and use a C library designed 
for microcontrollers (e.g. newlib) it's not a problem.  It appear 
the bloat mostly comes from the standard library, not the 
language.

A recent pull request to GDC 
(https://github.com/D-Programming-GDC/GDC/pull/505#event-1141470083) removed much of the TypeInfo bloat that was generated when using classes, which has reignited some interest in using D for microcontrollers.  Perhaps there's something in that pull request for other compiler developers to learn from.

Mike




More information about the Digitalmars-d mailing list