Checklist: Basic Data Type
Introduction to Numerical
- Avoid the use of numeric codes mysterious
- Code division by zero error taken into account yet?
- Cast it obvious?
- If two different types of variables exist in a single statement, this statement would like to ask you expect the value of that right?
- Code to avoid the mixed-type comparison of it?
- The program does not do a compile-time warning message?
Integer
- Use integer division expression will work as expected it?
- Integer expression to avoid integer overflow problem?
Float
- Code avoiding the huge number of orders of magnitude difference between addition and subtraction to do it?
- Code system to prevent rounding errors happen?
- Code to avoid bright lights floating point numbers do compare it?
Characters and Strings
- Avoid using the code string of mysterious and mystical character yet?
- Avoid off-by-one error when you use a string?
- C bar code string array of pointers to character differences and treat it?
- C code follows a string declared CONTANT + 1 length yet?
- C code at the appropriate time with a character array pointer to replace it?
- C code to initialize it to NULL strings to avoid an endless string of yet?
- C code using strncpy () instead of strcpy () it? strncat () and strncmp () do?
Boolean variable
- Program with additional Boolean variable to explain the condition judgment yet?
- Program with additional Boolean variables to simplify conditional yet?
Enumerated type
- Program rather than an enumerated type named constants used to improve readability, reliability, and modifiability yet?
- When the use of a variable can not just true and false representation of time, the program to replace it with a Boolean variable enumeration type?
- For enumerated type of test to detect the illegal value it?
- The first entry in the enumerated type reserved for the "illegal" yet?
Named Constant
- Program name appliances rather than mysterious numerical constants declared data and the limits of the cycle yet?
- Consistent use of named constants do? - do not use named constants in some position and amount of text to use in other locations?
Array
- All array indexes do not go beyond array boundaries do?
- Array reference no off-by-one errors it?
- Under the subject of the order are all multidimensional array correct?
- In nested loops, the correct variable for the array subscript to avoid the next cycle marked crosstalk yet?
Creating type
- Program using different types of data every possible change you?
- Type the name of the entity is to show the world the type represented oriented rather than oriented programming language type it?
- Type a descriptive name that is strong enough, it can help explain the data declared it?
- You avoid redefine the predefined type?
- Compared with the simple re-define a type, you considered creating a new class do?
Points
- Use a specific type of data would mean a lot to keep in mind the principle of independence applicable to each type. Be sure you have to frequently asked questions do consider using the checklist in this chapter.
- If your language support, create custom types will make your program easier to modify and more self-descriptive
- When you create a simple type with typedef or its equivalents when considering whether more should create a new class
Reproduced in: https: //www.cnblogs.com/taceywong/p/8718364.html