0

I know that in general case int size is compiler-dependant, but as Linux and other *nixes use int as a file descriptor and are required by POSIX to be able to send the file descriptors through UNIX sockets via cmsghdr structure, is there a specification that say how large is int exactly? Otherwise 2 different compilers could end in ABI incompatible code.

I couldn't find any definitive standard except mention in IBM Knowledge Base that states that int is 4 bytes on UNIX and Linux on both 64-bit and 32-bit platforms.

Hauleth
  • 22,873
  • 4
  • 61
  • 112
  • It's more that combination of platform+OS. POSIX definitely never would define size of an int. `Otherwise 2 different compilers could end in ABI incompatible code.` Yes, and that can happen, even with the same compiler. For example https://stackoverflow.com/questions/18133812/where-is-the-x86-64-system-v-abi-documented – KamilCuk Jul 09 '20 at 09:19
  • I guess POSIX by virtue of specifying the contents of `stdint.h`? https://pubs.opengroup.org/onlinepubs/9699919799/ – gstukelj Jul 09 '20 at 09:29
  • 1
    Does this answer your question? [Where is the x86-64 System V ABI documented?](https://stackoverflow.com/questions/18133812/where-is-the-x86-64-system-v-abi-documented) – KamilCuk Jul 09 '20 at 09:35
  • 1
    [64-Bit Programming Models: Why LP64?](http://archive.opengroup.org/public/tech/aspen/lp64_wp.htm) is rather old (pre-C99, judging by the "long long, a non-standard datatype" bit), but that describes why LP64 was chosen for UNIX and UNIX-like systems. And [here's the reasons why Windows chose LLP64](https://learn.microsoft.com/en-us/windows/win32/winprog64/abstract-data-models). [64-bit computing: 64-bit data models](https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models) is also informative, and the table provides info on the data models used by various sample platforms. – MemReflect Jul 10 '20 at 02:50
  • Linux also currently supports an ILP32 programming model on 64-bit platforms natively called the [x32 ABI](https://en.wikipedia.org/wiki/X32_ABI). It is kinda the same as the x86 (i386) ABI, except that it can take advantage of the x86-64 ABI with the exception that you are still limited to 4 GiB of memory. However, [whether it sticks around or not](https://lkml.org/lkml/2018/12/10/1145) remains to be seen. [Debian's "popularity contest" x32 stats](https://popcon.debian.org/stat/sub-x32.png) indicates rare usage of x32, and the long LKML discussion suggests maintenance is difficult. – MemReflect Jul 10 '20 at 03:36

0 Answers0