Your code is defective.
The correct way to optimize compile time on strlen() , oddly enough, just calls strlen() . a modern compiler like clang will optimize unnecessary strlen() when it knows the length at compile time.
In addition, in most cases, sizeof comes in handy when you, the programmer, use it correctly if the variable contains literal strings. as:
const char foo[] = "Hello World"; size_t len = sizeof(foo)-1;
Note that this has some kind of assumption, and if you do this, you make problems, but don't make your life simple:
const char foo[] = "Hello World\01234"; size_t len = sizeof(foo)-1;
EDITED: to make the obvious more like an answer.
Non-maskable interrupt
source share