Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Constant table but dynamic initialization at runtime
#include <cstdio> #include <cstdint> #include <stdlib.h> enum class Mode : uint16_t { // Changing to bool removes the warning. Hello, World }; struct Foo { union { struct { Mode mode : 1; // Warning here with gcc. uint32_t b : 16; }; uint32_t x; }; Foo(Mode mode) : mode(mode), b(0) {} Foo(Mode mode, uint32_t b) : mode(mode), b(b) {} operator uint32_t() const { return x; } }; const uint32_t DataTable[] = { Foo(Mode::Hello), Foo(Mode::World, 8), Foo(Mode::Hello, 4), 1,2,3, }; void PrintData(size_t idx) { printf("x = %d\n", DataTable[idx % 6]); } int main() { PrintData(rand()); return 0; }
run
|
edit
|
history
|
help
0
sample ptr and obj ex
Dequeue Using STL List
лаб1
Copy_and_base
#31
javascritp
empty base bug
kkk
Error log b is an undeclared identifier...
5sdgts