When I tried to use the sizeof operator to determine the exact size of some objects, I got zero as the result. What is wrong?
You probably tried something like printf (“%d”, sizeof (something)); The ANSI standard proposes that the sizeof operator returns a value of type size_t, which is in fact long integer in this implementation. So, the result is pushed on the stack as a long integer, but the format specifier “%d” expects an ordinary integer, so it pulls from the stack just one word, which is zero in this case. You need to write printf (“%ld”, sizeof (something)); Alternatively, you can use a typecast to convert the result to a short integer printf (“%d”, (short) sizeof (something)); assuming that no object would be longer that 32767 bytes.
Related Questions
- When I tried to use the sizeof operator to determine the exact size of some objects, I got zero as the result. What is wrong?
- iSeries / AS400 FAQ : (Category) Programming : How can I determine the size of objects in the IFS?
- Is it possible to determine the size of the function using the sizeof operator?