This article is taken from the "DR.Dobb's Software R & D" fourth phase (THE NEW C: C99 "in November 2003), which is obtained by the author Randy Meyers and" Dr.dobb's Software R & D "Mr. Liu Jiang, the head of the magazine, published the previous part of the full text as a document, hoping to help everyone.
THE NEW C: Integer Part 1 in C99
Translation: This article is the third article of the New C, along with the fourth division of the fourth author, mainly tested the change in C99 and new standards. Interest (int) as the basic data type in C language, the status is irreplaceable for C programmers. This article gives assistance to the Critical C language and users who use C language in new C languages. Everything about this article can be contacted and discussed with the translator with amstrongest@hotmail.com.
The C language originated in some non-type languages, but it has more connotations compared to those simple non-type languages.
Go back to the 1980s (1980s), the function of the ANSI C standard and defined function prototype did not introduce, and some fierce arguments about the C language type system were occasionally occurred on the Comp.lang.c newsgroup. The cause is generally the supporters of Pascal accuse the C language lack of strict types of types. Beyond pure objection, C camp sometimes has a fair-to-a-kind knead that kills all types of checks. One of them once this message: "C language does not need strong type, because c programmers use three types: integer, characters, and character pointers."
This exaggerated statement itself is a little humorous, but how much it reflects some real situations. In many C language programming, especially system programming, different scales are all basic data types. Of course, you can also store integers with arrays and structures. Sometimes the integer represents a figures, but sometimes they represent characters, but almost all things are one of them or their evolution. The basic data type of the Snobol language is String. Fortran is floating-point number, but for C, it is integer.
This is not to say that there is no new and important floating point characteristics in C99, as this new feature does exist. However, for most C programmers, integrity is still the core. In this month and next-month column, I will tell the new characteristics of integer in C99.
No longer the default type
C is evolved from the non-type language BCPL and B. Its itself is also non-type language in the short period of development. Non-type languages are not really complete, more accurately, they should have only one type ---- Machine Word, but most of them treat it as an integer. There is no doubt that in those languages are not required to include Type Specifier, because only one of the languages (but no types of names) are valid. When Dennis Ritchie first adds the type to the C language, it is only intellectual and characters. I don't know if such a behavior is the foundation of the C language is a non-type language, or the prestige of integer in the C language comes from this, or this is also the famous conciseness of the C language. In any case, the C language has always been the default data type of the language before the source starts from its source to the C99. If you declare an object or function without specifying its type, or by calling implicitly declared a function, these default types will be intellectual.
For example, before C99, if the following code belongs to a translation unit: Externx;
f (y)
{
Register z = g (x) y;
Return Z;
}
The types of variables x, y, and z will be intellectual, and the functions F and G are also returned. C99 requires that if you use the properties defined by early C language at any time ----- One type is integrated as its default value, the compiler gives a diagnosis. The benefits of giving a diagnosis are because many implicit integers will cause errors and such errors are not easy to locate. Just like the full translation unit below:
int main ()
{
Double D;
D = SQRT (2.0);
Return 0;
}
Because SQRT is implicitly declared, the compiler will return it to an integer. When SQRT is properly stored, the main function main does not need to know which location is stored in the return value (on some machines, integer variables and floating point variables use different registers), when the main function main loads this return When the value (from possibly wrong place), this value will be converted into a Double type in order to assign it to the d. Because the return value itself is already a double type (assuming that the main function main is correctly found), this will cause the SQRT return result to completely confusion.
In many cases, this property can be caused. For example, you may contain the wrong header file and miss the required function declaration, or forget the type of type when declaring an external variable. Implicit integer features will bring convenience and will also bring huge difficulties in finding murder errors. Even Ritchie I also mentioned that he likes the compiler that enforces the prototype declaration.
Note that C99 does not require a compiler to terminate compilation of implicit integer diagnostics as an error. A smart compiler will only see the diagnosis as a warning, and according to the selection of the programmer is to give an error message or completely ignore it.
-Finish-
Welcome: http://nishuo.35123.net