When reading nginx source code, I find this line:
#define NGX_INT32_LEN sizeof("-2147483648") - 1
why using sizeof(“-2147483648”) – 1?
not sizeof(-2147483648) – 1
not -2147483648 – 1
not -2147483649
or else?
What’s the difference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically -2147483648 is the widest, in terms of characters required for its representation, of any of the signed 32-bit integers. This macro
NGX_INT32_LENdefines how many characters long such an integer can be.It does this by taking the amount of space needed for that string constant, and subtracting 1 (because
sizeofwill provided space for the trailing NUL character). It’s quicker than using:because not all compilers will translate that into the constant
11.