bytes of each variable

Source: Internet
Author: User

Win64, which is the X64 compilation configuration:

Char 1 bytes;

Short 2 bytes;

int 4 bytes;

Long 4 bytes;

A long long 8 bytes;

Float 4 bytes;

Double 8 bytes;

A long double of 8 bytes;

wchar_t 2 bytes;

BOOL 1 bytes;

(The pointer is all 8 bytes)

char* 8 bytes;

bool* 8 bytes;

short* 8 bytes;

int* 8 bytes;

long* 8 bytes;

Long long* 8 bytes;

float* 8 bytes;

double* 8 bytes;

Long double* 8 bytes;

wchar_t* 8 bytes;

Here is the Win32, which is the number of bytes in the X86 compiler configuration

Char 1 bytes;

Short 2 bytes;

int 4 bytes;

Long 4 bytes;

Longlong 8 bytes;

Float 4 bytes;

Double 8 bytes;

A long double of 8 bytes;

wchar_t 2 bytes;

BOOL 1 bytes;

(The pointer is all 4 bytes)

char* 4 bytes;

bool* 4 bytes;

short* 4 bytes;

int* 4 bytes;

long* 4 bytes;

Long long* 4 bytes;

float* 4 bytes;

double* 4 bytes;

Long double* 4 bytes;

wchar_t* 4 bytes;

Other types:

Enum type declaration does not account for memory.
eg. Enum Color {Red, Black}; does not account for memory.

The enum variable definition accounts for the int type memory. The Win32 is 4B.
eg. Color CLR; account for sizeof (int)

Member alignment issues for structs:

For structs, the compiler automatically aligns the members to improve the efficiency of the operation. By default, the compiler allocates space for each member of the struct by its natural alignment (aligned by the largest member of the member in the struct), and each member is stored sequentially in memory in the order in which they are declared.

The structure of a Union (union) is large enough to be equal to the space of one of the longest structure variables, but this longest space satisfies the following conditions:

1. Space greater than or equal to the longest one structure variable

2. And to be able to divide the data length of other structural variables (length least common multiple of the meta-type length).

Summary: Compared with the above, the general variables in the X86 and X64 system length of no difference, the difference is that the range of the pointer is increased from 32 to 64 bits. If you consider the compatibility of programs under 64-bit systems, pointers are the only place to be aware. Transitioning from a 32-bit system to a 64-bit system differs from transitioning from a 16-bit system to a 32-bit system, because the DOS system has only 2 bytes under int, and the Windows system under int is 4 bytes, and the byte count of int is not incremented after transitioning to a 64-bit system. If you use Windows system programming, support for 64-bit requires visual Studio 2005/2008, and earlier versions do not support 64-bit platforms.

bytes of each variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.