For portability that question already talks a little about, where @Maniero responds:
Defined behaviour
In fact most behaviors are defined by the specification and for an implementation conform to the
specification needs to do exactly what she says. Good. By
be normal and there’s no definition of it.
If your code needs to be portable, only defined behaviors
should be used, or the other three forms of behavior need
be properly addressed in each compilation environment in a
individual.
According to the answers that question in Soen, no specification guarantees, nor POSIX, of size occupied in memory that a type variable short
, int
and long
shall have. In return for draft of the specification you have the guarantees of "minimum values":
Their implementation-defined values Shall be Equal or Greater in
magnitude (Absolute value) to those Shown, with the same Sign.
For example, in my system:
#include<stdio.h>
#include<limits.h>
int main(void){
printf("The value of INT_MAX is: %d.\n", INT_MAX);
printf("The value of INT_MIN is: %d.\n", INT_MIN);
}
Whose result is:
mateus@debian:~/desk$ ./a.out
The value of INT_MAX is: 2147483647.
The value of INT_MIN is: -2147483648.
Note that the value of INT_MIN
in my system is minor than the specification, but in absolute values my machine is larger, and therefore in this case meets the specification.
Still in draft §5.2.4.2.1:
minimum value for an Object of type short int
SHRT_MIN -32767 // (2 15 1)
Maximum value for an Object of type short int
SHRT_MAX +32767 // 2 15 1
minimum value for an Object of type int
INT_MIN -32767 // (2 15 1)
Maximum value for an Object of type int
INT_MAX +32767 // 2 15 1
minimum value for an Object of type long int
LONG_MIN -2147483647 // (2 31 1)
Maximum value for an Object of type long int
LONG_MAX +2147483647 // 2 31 1
What I wrote is about C11, the book goes back, although I can’t guarantee that it met the older standards of the language, because I don’t know it myself.
Some useful links: http://linguagemc.com.br/tipos-de-dados-em-c/ and https://stackoverflow.com/questions/35844586/can-i-assume-the-size-of-long-int-always-4-bytes
– Maury Developer
Here is an example of the real world. For the following code:
#include <stdio.h>

int main ()
{
 printf("sizeof(long) = %zu\n", sizeof(long));
 return 0;
}
Output on Debian 7 i686:sizeof(long) = 4
Output on Centos 7 x64:sizeof(long) = 8
– Maury Developer
It seems the author commented an error in stating that the prefixes define a single size for any architecture.
– Fabricio Paiva
Do you have link book? I want to read this book,to see me the best excerpt.
– Maury Developer
http://www.ams.eti.br/booklets/Luis_Damas.pdf page 42 of the pdf
– Fabricio Paiva
He missed badly.... I don’t know anything C, but I knew it. The values in memory are 8(long) bytes and 4(short) bytes.
– Maury Developer