Skip to content

Commit

Permalink
Fixing parens and adding an explaination comment
Browse files Browse the repository at this point in the history
  • Loading branch information
LeStarch committed Sep 25, 2024
1 parent 34c1453 commit 469d679
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Os/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
#include <Fw/Types/Assert.hpp>
#include <new>

alignas(Os::Console) U8 _singleton_store[sizeof Os::Console];
// While we desire the singleton to be in global space to avoid placing
// such object on the heap, the singleton must be constructed at first
// request due to C++'s undefined ordering of constructors between
// compilation units.
//
// To meet both requirements, we place an aligned and sized block of
// memory on the in global space as seen here, and then placement-new
// the singleton into that region. Thus constructing on the fly while
// avoiding heap usage.
alignas(Os::Console) U8 _singleton_store[sizeof(Os::Console)];

Check notice

Code scanning / CodeQL

Variable scope too large Note

The variable _singleton_store is only accessed in
getSingleton
and should be scoped accordingly.

namespace Os {
Console* Console::s_singleton;
Expand Down

0 comments on commit 469d679

Please sign in to comment.