I am inspired by this answer.
The one way I thought of was a combination of static_assert
(C11-onwards) and assert
.
Basically, an ascii.h
file with a bunch of
static_assert(' ' == 32);
static_assert('!' == 33);
// ...
statements and then a function
static void assert_runtime_ascii(void) {
assert(' ' == 32);
assert('!' == 33);
// ...
}
to be executed in main
.
This is way too verbose (200+ lines) making this impractical, so I just comment this
// NOTE: this program expects ASCII both at run-time and compile-time.
and be done.
Is there a better way?
I could not find a #define
like __STDC_IEC_559__
for ASCII in the standard.
Is there a better way?