Re:Wordlexpr: Compile-Time Wordle in C++20
by nneonneo on Monday February 28, 2022 @04:20AM
(#30497958)
Neat hack! One minor improvement suggestion: if you seed the RNG with `__DATE__` (or a hash of that string), then you can replicate the one-puzzle-a-day experience with no need for an externally-supplied seed variable.
[ Parent
| on HN ]
Re:Wordlexpr: Compile-Time Wordle in C++20
by SuperV1234 on Monday February 28, 2022 @10:14AM
(#30500677)
Good point! I wanted to be able to modify SEED in order to test that everything was fine with multiple words, using __DATE__ didn't come to mind :)
Re:Wordlexpr: Compile-Time Wordle in C++20
by TheSoftwareGuy on Monday February 28, 2022 @11:37AM
(#30501817)
#ifndef SEED
#define SEED __DATE__
#endif
Re:Wordlexpr: Compile-Time Wordle in C++20
by fathyb on Monday February 28, 2022 @04:40AM
(#30498087)
Wondering what happens if you allocate a chunk of uninitialized memory inside a constexpr? Could this be used for a quick constexpr RNG seed?
Re:Wordlexpr: Compile-Time Wordle in C++20
by jcelerier on Monday February 28, 2022 @05:59AM
(#30498548)
A 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.
Re:Wordlexpr: Compile-Time Wordle in C++20
by xroche on Monday February 28, 2022 @04:54AM
(#30498178)
You 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.