4 ms·
Wondering what happens if you allocate a chunk of uninitialized memory inside a constexpr? Could this be used for a quick constexpr RNG seed?
by fathyb 5y ago
Wondering what happens if you allocate a chunk of uninitialized memory inside a constexpr? Could this be used for a quick constexpr RNG seed?
- xroche 5y agoYou simply can't. The constexpr environment won't let you have uninitialized variables/memory anywhere. It won't let you access dangling/out-of-bounds pointers either, overflow two-complement types, etc.
- flqn 5y agoAccessing uninitialized objects is undefined behaviour, which traps in the constexpr context.
- jcelerier 5y agoA very neat thing of constexpr is that it does not have undefined behaviour ; any thing that would cause UB at run-time is flagged as a compile error. Every variable must be fully initialized.