Search code examples
csizeof

Conflict in the Sizeof Long


I checked on the net it shows size of long to be 4 bytes . But when I print sizeof(long) in my laptop it prints 8 . Why is there a conflict in the values ? I am using this print statement

printf("%zu",sizeof(long));

Solution

  • The "conflict" you mean to see comes from the standard, which does not specify specific widths of the integer types. Different compilers use different widths.

    But the real question you have is: "What should I do?"

    The answer is to use the types provided by the standard for such purpose. Include "stdint.h" and use int32_t (or uint32_t for unsigned integers) for 4-byte integers.

    Please get yourself a standard, and take the time to look in it. You don't need to read every line, though, just enough to know what to expect therein.