Determine #defined string length at compile time

后端 未结 4 2025
抹茶落季
抹茶落季 2021-02-07 01:28

I have a C-program (an Apache module, i.e. the program runs often), which is going to write() a 0-terminated string over a socket, so I need to know its length.

4条回答
  •  遥遥无期
    2021-02-07 01:55

    Use sizeof(). e.g. sizeof("blah") will evaluate to 5 at compile-time (5, not 4, because the string literal always includes an implicit null-termination character).

提交回复
热议问题