Catalog: 12.1 Numerical Introduction
12.2 integers
12.3 floating Point
12.4 Characters and strings
12.5 Boolean variables
12.6 Enum Types
12.7 named constants
12.8 arrays
12.9 Create your own type
12.1 Introduction to numerical values
The base data type is the block that makes up the data
First, avoid the use of mysterious values
Second, if necessary, you can use hard-coded 0 and 1
Iii. prevention of the exception of 0 errors
Iv. making the conversion of types become apparent
V. Avoiding mixed-type comparisons
VI. Note Compiler warnings
12.2 integers
One, check integer division
Second, check the integer overflow
Third, check the intermediate result overflow
12.3 floating Point
One, to avoid the magnitude difference between the number of the addition and subtraction operations
Second, avoid the equal judgment
Iii. Handling Rounding Error problems: Calculation with higher precision values
Iv. checking language and library support for specific data types
12.4 Characters and strings
First, avoid the use of mysterious characters and mysterious strings
Second, avoid off-by-one errors
Third, understand how your language and development environment support Unicode
Iv. determining internationalization and localization strategies as early as possible in the program life
If you know that you only need to support the language of one text, consider using the ISO8895 character set
Vi. If you need to support multiple languages, use Unicode
Vii. adopting some consistent string-type conversion strategy
Strings in the C language
Note the difference between a string pointer and a character array
Nine, the length of the C-style string is declared as Constant+1
Initialize a string with NULL to avoid a string without a terminator
Xi. replacing pointers in C with character arrays
12. Replace strcpy with strncpy () to avoid a string without a terminator
12.5 Boolean variables
First, using Boolean variables to document the program description
Second, using Boolean variables to simplify complex judgments
Third, create your own Boolean type if needed
12.6 Enum Types
I. Using enumeration types to improve readability
Ii. increasing reliability with enumeration types
Third, use enumeration type to simplify the modification
Iv. The enumeration type as an alternative to a Boolean variable
V. Checking illegal values
Vi. define the first and last items of the enumeration for use with circular boundaries
Vii. leave the first element of the enumeration type as an illegal value
Viii. define the rules for the use of the first and last elements in the project code authoring standard, and maintain consistency when used
Nine, alert to the enumeration elements of the explicit assignment of errors caused by
12.7 named constants
One, the use of a named constant in the data declaration
Second, avoid the use of text, even if it is safe
Iii. using variables or classes with appropriate scopes to simulate named constants
Iv. uniform use of named constants
12.8 arrays
First, verify that all array subscripts do not exceed the bounds of the array
Consider replacing an array with a container (set, stack, queue), or using an array as a sequential structure
Third, check the boundary point of the array
Iv. if the array is multidimensional, confirm that the subscript is in the correct order of use
Five, beware of the next standard series of words
Six combine array_length () macros in C to use arrays
12.9 Create your own type
Principle: 1, to the creation of the type of function-oriented name
2. Avoid using predefined types
3. Do not redefine a pre-defined type
4. Define alternative types for portability
12th Chapter Fundamental Data Types Basic datatype