Why are C++ int and long types both 4 bytes?

前端 未结 8 1064
栀梦
栀梦 2020-12-01 10:49

Many sources, including Microsoft, reference both the int and long type as being 4 bytes and having a range of (signed) -2,147,483,648 to 2,147,483,647. What is the point of

8条回答
  •  难免孤独
    2020-12-01 11:37

    The C++ Language Specification simply states that the size of a long must be at least the size of an int.

    It used to be standard to have int = 2 bytes and long = 4 bytes. For some reason int grew up and long stayed the same (on Windows compilers at least). I can only speculate that long was kept the same for reasons of backwards compatibility...

提交回复
热议问题