flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > About size in 64 bit Bool,Uint,Enum

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1847
Roman 22 Sep 2019, 06:58
How bytes in 64 bit c++ program:
Bool,Uint,Enum


I think bool = 4 bytes, uint = 4 bytes , enum = 4 bytes
Its right ?

Its need for this struct:
Code:
typedef struct DXGI_SAMPLE_DESC {
  UINT Count;
  UINT Quality;
} DXGI_SAMPLE_DESC;

typedef struct DXGI_SWAP_CHAIN_DESC1 {
  UINT             Width;
  UINT             Height;
  enum DXGI_FORMAT      Format;
  BOOL             Stereo;
  DXGI_SAMPLE_DESC SampleDesc; this struct two uint
  enum DXGI_USAGE       BufferUsage;
  UINT             BufferCount;
  enum DXGI_SCALING     Scaling;
  enum DXGI_SWAP_EFFECT SwapEffect;
  enum DXGI_ALPHA_MODE  AlphaMode;
  UINT             Flags;
} DXGI_SWAP_CHAIN_DESC1;
    
Post 22 Sep 2019, 06:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20445
Location: In your JS exploiting you and your system
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.
Post 22 Sep 2019, 08:58
View user's profile Send private message Visit poster's website Reply with quote
QuarkMan



Joined: 21 Sep 2019
Posts: 6
Location: Suzano - São Paulo - Brasil
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.
Post 22 Sep 2019, 20:20
View user's profile Send private message Reply with quote
fpissarra



Joined: 10 Apr 2019
Posts: 64
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...
Post 24 Sep 2019, 14:34
View user's profile Send private message Reply with quote
fpissarra



Joined: 10 Apr 2019
Posts: 64
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.
Post 24 Sep 2019, 14:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.