by dantle · 3y ago · 0 comments
1. %n in printf would be handy when writing CLIs dealing w/ multiple lines or precise counts of backspaces.
2. Using enums as a form of static_assert() is a great idea (triggering a div by zero compiler error).
%n is for bytes, not user-perceived characters.
#define STATIC_ASSERT(COND) extern char static_assert_cond_[(COND)?1:-1] /* C99 or earlier */
#define STATIC_ASSERT(COND) _Static_assert(COND) /* C11 or later */
As both are declarations, I don't think you'll end up in a situation where one is valid and the other isn't - but I could be wrong, and I suspect it would rarely matter in practice anyway.