The difference between C–k&r C and ANSI C

Source: Internet
Author: User
Tags arithmetic constant


Article reprinted from: http://www.cnblogs.com/huangjacky/archive/2012/05/04/2482529.html



the difference between C–k&r C and ANSI C



Recently in the book "C and Pointers", the book has repeatedly mentioned K&r C,ansi C we often hear, and this is not very clear, I have to go to Baidu, especially to do the following record.


The C language was designed and implemented by Dennis M. Ritchie in 1973. Since then the users gradually increased. By 1978 Ritchie and Bell Labs, another program expert Kernighan wrote the famous "The C programming Language", the C language to the world, many countries have translated, There are some C language books in China is the translation or compilation of this book. The C language, defined by the book, was later called K&r C.
With the use of C language more and more widely, there are many new problems, people are increasingly demanding the standardization of C language. This standardized work was carried out in the framework of the United States National Standards Office (ANSI) (1983-1988), and the final result was the ANSI standard x3.159-1989 promulgated in October 1988, which was later referred to as the ANSI C standard. The C language defined by this standard is called ANSI C.
The ANSI C standards were soon adopted as international standards and national standards. International standard is ISO/IEC 9899-1990, China National standard GB/T 15272-94 is a Chinese translation of ISO standard.
One of the main objectives of ANSI C standardization work is to remove the unsafe, unreasonable, imprecise and imperfect things in the original C language. This also results in the difference between ANSI C and K&r C. On the whole, these differences respond to the C language to perfect and mature.


the revision of ANSI C to k&r C (This paragraph is organized in accordance with the C programming Language and the C language standards.) Do not complete, want to list the most common differences) 

1. For the identifier inside the source file, the effective minimum length is expanded to 31 characters. When connecting between files, the minimum valid length of the identifier is still 6 characters. (Many implementations support larger lengths)
2. Added several new keywords: void, const, volatile, signed, enum. Abandoned the old keyword entry.
3. After the non-specified sequence is written after the character \, the role is determined to be undefined.
4. It is stipulated that 8 and 9 are not legal characters of octal numbers.
5. Introduced a number of suffix characters: U and L for integers, F and L for floating point numbers.
6. Specifies that string constants that appear consecutively will be stitched together.
7. Introduced the concept of "wide character".
8. Characters are also determined to be signed (signed) and unsigned (unsigned).
Long float (used as a synonym for double).
9. Introduced the void type, using (void*) to indicate the type of the generic pointer (in the past people used (char*)).
10. The minimum representation range is specified for the arithmetic type. Each C language system is required to use the header files (<limits.h>; and <float.h>;) to specify the implementation details.
11. Introduced the enumeration definition enum.
12. Type modifiers from C++, such as const.
13. Specifies that string constants are not modifiable.
14. Changed the implicit conversion rules for arithmetic types.
15. Deleted some obsolete assignment operators, such as =+. The specified assignment operators are all basic words, such as += can not be separated by spaces.
16. Introduced the unary + operator corresponding to the unary-operator.
17. Pointers to functions can be placed directly at the location of the function call without having to explicitly write indirect operations.
18. Allow structurally global assignments to be passed as function arguments and return values.
19. Allows the address operator to be applied to the array, resulting in a pointer to the array.
The standard specifies that the return value of the sizeof operator is of type size_t (an unsigned integer) defined in the standard header file <stddef.h>; Also defined there is the ptrdiff_t type, which is the result type of the pointer subtraction.
20. The specified address operator cannot be applied to the register variable.
21. Specify the type of the shift expression to be the type of the left operand.
22. Allows the creation of a pointer to a position at the end of the array, as well as arithmetic and relational operations on it.
23. (From C++) Introduced the concept of function prototypes containing parameter types, introducing the concept of variable-length parameter table functions. Old forms are still allowed, but are only reserved as obsolete forms.
24. The standard states that the scope of any local declaration is simply the current block (composite statement).
The function parameters are specified as declarations added to the body of the function (composite statement), so they cannot be overridden with variable declarations.
25. The rules for namespaces: all structures, unions, and enumerations are in one namespace, and labels are another namespace.
26. The joint variable can also be initialized when defined, specifying the initialization of its first component.
Automatic structures, unions, and arrays can also be initialized, but their initialization is limited (which can only contain constant expressions).
27. A character array with a size description can also be initialized with a string constant of the same size (the end of \0 is deleted).
28. The control expression and case label of the switch statement can be any integer (including the character type).

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.