Why does sizeof(int) vary across different operating systems?

后端 未结 4 1729
-上瘾入骨i
-上瘾入骨i 2020-12-02 00:55

I wounder why size of int depends on which OS one is using ,in C & C++. It\'s ok if size of pointer varies, but why size of integer. If 16 bit OS sizeof(int) = 2 byte, f

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 01:20

    Your question can be reformulated as why the different types of data structure depends on the CPU. This can be justified simply by the fact that C is a language that can be used in low-level programming. You can see in Data Types in the Kernel how that data types are defined for different types of CPU in Linux. This is link to word length of the processor.

提交回复
热议问题