[Reprinted 3] integrity in CC ++

xiaoxiao2021-03-06  40

Many people in C / C have a lot of people in C / C , causing problems when code transplantation, I summarize, if I have a description, be sure to point out, thank you!

a. C / C specified for integer length To perform efficiency, definition INT as the machine word length can achieve maximum execution speed; B. C / C integrates: int, char and enum, C also included Bool type, BOOL in C99 is a macro, actually _bool; c. C and C have different rules for ENUM, not described here; d. Modified integer positive and negative Signed and unsigned, for Int defaults Signed , E.Mecking the INT size, SHORT and Long, some compilers also extend some longer integers, such as long long and __int64, c99 adds long long and unsigned long long; f. int, length and machine The word length is the same, and the INT length is 16 bits on the 16-bit compiler. It is 32 bits on the 32-bit compiler; g. Short int is less than or equal to the length of INT, pay attention to the length of them, depending on the compiler; h. long int range is greater than or equal to the length of int, pay attention to the length of them, depending on the compiler; i. Char length should be able to allow the next character, most of the system is one byte, and some system It may be 4 bytes because one character in these systems requires four bytes; J. CHAR's positive negative depends on the compiler, and the compiler decision depends on the operating system, in different compilers, CHAR It may be equivalent to Signed Char, or may be equivalent to unsigned char;

Summary: a. For efficiency, Int and unsigned int; b should be used as much as possible when you need to specify the integer, Short, Int, long, etc. should not be used directly, because their capacity is not in different compilers. the same. In this case they should define the appropriate macros or type, such as the VC 6.0 can be defined as follows: typedef unsigned char UBYTE; typedef signed char SBYTE; typedef unsigned short int UWORD; typedef signed short int SWORD; typedef unsigned int UDWORD; TypedEf Signed Int SDWORD; TYPEDEF Unsigned __INT64 uqword; typedef sign; then use Ubyte, Sbyte, UWORD, etc. in the code, so when the code is transplanted, you only need to modify the corresponding type. Define your own types, although you only need to modify one at the code transplant, but still belong to the source code level, so these types are defined in the template in C 2.0, and you can do this type without modifying the code. c. When defining char, you must add Signed or unsigned because her positive and negative is not the same on different compilers. d. Don't think of that CHAR is a 1-byte length, because her length is not the same on different compilers.

转载请注明原文地址:https://www.9cbs.com/read-59669.html

New Post(0)