Can I assume the size of long int is always 4 bytes?

前端 未结 10 840
闹比i
闹比i 2020-12-07 18:26

Is it always true that long int (which as far as I understand is a synonym for long) is 4 bytes?

Can I rely on that? If no

10条回答
  •  心在旅途
    2020-12-07 18:50

    Short answer: No! You cannot make fixed assumptions on the size of long int. Because, the standard (C standard or POSIX) does not document the size of long int (as repeatedly emphasized). Just to provide a counter example to your belief, most of the 64 bit systems have long of size 64! To maximize portability use sizeof appropriately.

    Use sizeof(long int) to check the size, it returns the size of long in bytes. The value is system or environment dependent; meaning, the compiler determines the size based on the hardware and OS.

提交回复
热议问题