News for hackers. Stuff that matters.
Re:C++ on Embedded Systems by shortoncash on Monday February 20, 2017 @06:07PM (#13691845)
This was an enjoyable article.

Is it necessary to call the constructors in the manner specified in the article? What would be the problem with using placement new in a designated block of memory?

Re:C++ on Embedded Systems by mrkline on Monday February 20, 2017 @07:33PM (#13692262)
The approach I laid out makes sure that the constructors for all of your global/static objects get called. AFAIK, there's no reason you couldn't do everything "by hand", but it seems like a lot more work for questionable gain.
Re:C++ on Embedded Systems by Espressosaurus on Tuesday February 21, 2017 @03:40AM (#13694231)
I prefer forcing a top-down initialization using placement new for any extent globals, that way initialization order can be carefully controlled. E.g. the OS gets started before we even bother bringing anything else up, other initialization happens in a separate task, then worker tasks are brought up, etc. Everything is sequenced, and we don't have to go to the linker script to figure out what's actually getting called.

Since the globals are singletons, any attempt to get their instance when they've already initialized is an error that will blow the program up. Helps keep us honest.

Re:C++ on Embedded Systems by shortoncash on Monday February 20, 2017 @09:25PM (#13692744)
Valid point.

However, there's no reason it has to be overly manual. As an example, you can make all the global object classes mixins for a variadic and use a variadic constructor and member methods to bring them all online in one fell swoop, even parameterizing construction via policy classes as template parameters. (Plus you have the added benefit of knowing via sizeof() on the variadic type the footprint of all the global objects.)

The gain would be to avoid the dependence on the linker script solution, particularly if tweaking linker scripts on a different compiler/build environments.