flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > About size in 64 bit Bool,Uint,Enum |
Author |
|
revolution 22 Sep 2019, 08:58
To be sure what size typedefs are you need to follow the definitions in the header files. Sometimes there are multiple levels to chase to find the raw type.
|
|||
22 Sep 2019, 08:58 |
|
QuarkMan 22 Sep 2019, 20:20
I think all variables in 64 bit are 8 Bytes length, but they are used like 4 Bytes.
Because 8 Byte alignment is better for 64 bits, but is necessary one more byte to encode all 64 bits registers. |
|||
22 Sep 2019, 20:20 |
|
fpissarra 24 Sep 2019, 14:34
What is garanteed is that sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long). The actual sizes depends on the architecture.
The _Bool (or bool in C++) type has the size of a char and, depending on the compiler, enums has the sizeof int or long (depending on how many enumerations there is). If you include limits.h you'll get the symbol CHAR_BIT defined which will give you the size of a character in bits (not necessarily of char TYPE). Your compiler can give you the sizes of most types via symbols as well, as in GCC: Code: $ gcc -dM -E - < /dev/null | grep SIZEOF #define __SIZEOF_FLOAT80__ 16 #define __SIZEOF_INT__ 4 #define __SIZEOF_POINTER__ 8 #define __SIZEOF_LONG__ 8 #define __SIZEOF_LONG_DOUBLE__ 16 #define __SIZEOF_SIZE_T__ 8 #define __SIZEOF_WINT_T__ 4 #define __SIZEOF_PTRDIFF_T__ 8 #define __SIZEOF_FLOAT__ 4 #define __SIZEOF_FLOAT128__ 16 #define __SIZEOF_SHORT__ 2 #define __SIZEOF_INT128__ 16 #define __SIZEOF_WCHAR_T__ 4 #define __SIZEOF_DOUBLE__ 8 #define __SIZEOF_LONG_LONG__ 8 These symbols gives you the sizeof these types in bytes. But, notice: No char or bool or enums are listed here. If you are using Windows, the MSABI (MicroSoft Application Binary Interface) says: char = 8 bits short = 16 bits int = 32 bits long = 32 bits pointers = 32 or 64 bits (depending if you are in i386 or x86-64 mode). If you are using Linux/MacOS/BSD, which follows SysV ABI: char = 8 bits short = 16 bits int = 32 bits long = 32 bits (i386) or 64 (x86-64) pointers = 32 bits (i386) or 64 (x86-64) There is also, the 'long long' type (present on C99+), which is 64 bits in size (but in these ABIs!). Notice the __int128 type extension in GCC as well (128 bits in size, of course). Alignment has nothing to do with types or data encoding... |
|||
24 Sep 2019, 14:34 |
|
fpissarra 24 Sep 2019, 14:51
If you are using GCC you can, also, do this:
Code: $ gcc -dM -E -D_GNU_SOURCE -include limits.h - < /dev/null | grep 'WIDTH\|WORDSIZE' #define LONG_WIDTH __WORDSIZE #define __SYSCALL_WORDSIZE 64 #define __INT_LEAST8_WIDTH__ 8 #define __INT_LEAST16_WIDTH__ 16 #define __SHRT_WIDTH__ 16 #define SCHAR_WIDTH 8 #define __INT_WIDTH__ 32 #define __PTRDIFF_WIDTH__ 64 #define __INTMAX_WIDTH__ 64 #define ULLONG_WIDTH 64 #define __INTPTR_WIDTH__ 64 #define USHRT_WIDTH 16 #define __WCHAR_WIDTH__ 32 #define LLONG_WIDTH 64 #define __LONG_LONG_WIDTH__ 64 #define SHRT_WIDTH 16 #define __SCHAR_WIDTH__ 8 #define __INT_FAST32_WIDTH__ 64 #define __SIZE_WIDTH__ 64 #define UCHAR_WIDTH 8 #define __SIG_ATOMIC_WIDTH__ 32 #define __WORDSIZE 64 #define UINT_WIDTH 32 #define __INT_FAST64_WIDTH__ 64 #define __WINT_WIDTH__ 32 #define __WORDSIZE_TIME64_COMPAT32 1 #define INT_WIDTH 32 #define __INT_FAST8_WIDTH__ 8 #define CHAR_WIDTH 8 #define ULONG_WIDTH __WORDSIZE #define __LONG_WIDTH__ 64 #define __INT_LEAST32_WIDTH__ 32 #define __INT_FAST16_WIDTH__ 64 #define __INT_LEAST64_WIDTH__ 64 Which will give you the width of these types in bits. |
|||
24 Sep 2019, 14:51 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.