The number of bytes in the base data type of C/__c++

Source: Internet
Author: User

Because of the different operating system memory allocation, resulting in the software development process, the need to compile different versions of software, here with VS for example.

1, compile the program according to need to choose different compilation environment:

X86 and Win32 bit 32-bit program, X64 64-bit program, can choose different editing conditions to form different bits of software.

2, the basic data type in the code, will be based on the operating system's number of digits allocated memory size:
such as int in the 32-bit operating system for 4 bytes, in 64-bit system for 8 bytes

So on the 64-bit on the INT data operation, compiling 32 of the program, may cause the int type out of bounds, software problems

3, 32-bit programs run on 64-bit operating systems, because of the problem of addressing and migration of 64-bit operating systems, it may also cause the program to run in a process where the results are inconsistent with the 32-bit system

4, 64-bit operating system can theoretically compatible with 32-bit and 64-bit software, 32-bit operating system can not run 64 programs

5, the use of VS2010 or VS2012 developed programs, forced to compile to 32-bit software, operating under the XP system is problematic, there may be a relationship with the. NET Framework version, the lower version of the framework can not support some controls or class libraries of the high version of the framework. Attempting to install a newer version of the framework to resolve a problem

To borrow Blog content:

A 64-bit system and 32-bit what is the difference.

1, 64bit CPU has greater addressing capabilities, maximum support to 16GB memory, while 32bit only support 4G memory

2, 64-bit CPU can extract 64-bit data at one time, more than 32-bit increased by one times, the theoretical performance will increase 1 time times. But this is based on the 64bit operating system, 64bit software.

What is a 64-bit processor.

It is called a "64-bit processor" because the internal computer is the implementation of 2, the processor (CPU) processing data at a time is also a multiple of 2. 8-bit processors, 16-bit processors, 32-bit processors, and 64-bit processors with a count of 2 multiples. The larger the data processed at one time, the greater the ability of the computer to process information, so that 64-bit processing is inherently faster than a 32-bit processor. So why not use a more advanced 128-bit processor? Because the higher the number of digits, the more complex the processor chip design, the current level of technology can not make such a complex chip.

Loss of 64-bit processor

※ Hardware ——— Lack of drivers, many existing hardware can not be used

※ Software ——— The operating system is not a problem, but the software incompatibility problem

The 64-bit processor

※ Hardware ——— faster execution speed and greater memory management

※ Software ——— The latest cutting-edge software first appeared on the 64-bit platform

(ii) number of bytes corresponding to the data type

Program running Platform
The number of bytes allocated to different data types on different platforms is different.
Personal understanding of the platform is cpu+os+compiler because:
1, 64-bit machine can also be installed 32-bit system (x64 installed XP);
2, 32-bit machine can have 16/32-bit compiler (XP on the TC is 16-bit, the other common is 32-bit);
3, even the 32-bit compiler can also make a 64-bit integer to (Int64).
These are based on common Wintel platforms, plus other platforms (other CPUs and OS) that we may have little access to, so the idea of a platform is a combination of the three.
Although the length of the three can be different, but obviously with each other (that is, the length of equal, 32-bit cpu+32 bit of the os+32 bit of compiler) to play the most energy.
Theoretically I think the byte number of the data type should be determined by the CPU, but it is essentially determined by the compiler (the number of bits that the compiler decides during compilation).

Common data types correspond to the number of bytes
can be derived as sizeof (char), sizeof (char*), etc.

32-bit compiler:

Char:1 bytes
Char* (that is, pointer variable): 4 bytes (32-bit address space is 2^32, that is, 32 bit, that is 4 bytes.) Empathy 64-bit compiler)
Short Int:2 bytes
Int:4 bytes
Unsigned int:4 bytes
Float:4 bytes
Double:8 bytes
Long:4 bytes
Long Long:8 bytes
Unsigned long:4 bytes

64-bit compiler:

Char:1 bytes
Char* (that is, pointer variable): 8 bytes
Short Int:2 bytes
Int:4 bytes
Unsigned int:4 bytes
Float:4 bytes
Double:8 bytes
Long:8 bytes
Long Long:8 bytes
Unsigned long:8 bytes


Reprinted from http://blog.csdn.net/nma_123456/article/details/45077345

Related Article

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.