Hacker News new | ask | show | jobs
by sixfiveotwo 662 days ago
> I can assure you that when writing code for microcontrollers with 2 kilobytes of code space, we don't include a 14 kilobyte string formatting library...

I'm pretty sure you wouldn't use C++ in that situation anyway, so I don't really see your point.

2 comments

If you get rid of the runtime, which most compilers allow you to do, C++ is just as suitable for this task as C. Not as good as hand-rolled assembly, but usable
Okay, vtables in 2kb code space?
Where are the vtables coming from if you use no inheritance and no memory allocation?
Why program in C++ if you don't use any of its features? You're just writing C in disguise.
A C in disguise with better strong typing, compile time programming that beats hands down the preprocessor, while having the preprocessor available if one insists in using it, being able to design abstractions with bounds checking, namespaces instead of 1960's prefixes,....
Template specialization means more generated code, which, again, must fit in 2kb.

On very old archs (16bits, 8bits), there was no OO, because the code could not be complex enough to warrant it. It could not be complex because there wasn't room enough.

That being said, there are templated libraries (like fmt...) which may result in zero overhead in code size, so if the thread OP is using C++, then surely he could also use that library...

I don't write anything new and use inheritance anyway.

Even in an embedded context you have classes and destructors, operator overloading and templates. You can still make data structures that exist in flat constrained memory.

Sure, but 2kb code space? What sort of class hierarchy can you possibly use in so little space?
You can use c++ yes and a lot of people do. You just keep the exceptions, stdlib and runtime in general at the door.