C and C + +

Source: Internet
Author: User
Tags function definition function prototype

C is a subset of C + +, which is a superset of C. C + + is based on the C language, the addition of object-oriented and generic programming features, expanded.

C language is a portable system language, originated from the development of UNIX operating system. C language is a flexible and efficient high-level programming language, but it also has some low-level language characteristics of machine-oriented, so some people call it a middle language. 1 Origin although early in April 1957 IBM (John W. Bacus) launched the first high-level programming language FORTRAN (FORmula translation formula conversion), 1958 GAMM/ACM (John W . Backus, Peter Naur, C. R. Hoare) has also introduced ALGOL (Algorithmic language algorithm language). But they are designed for mathematical and scientific calculations and are not suitable for system programming.

John Kemeny and Thomas Kurtz simplified Fortran in 1964 to invent the basic (beginners all-purpose symbolic Code basic beginner's General Instruction code) language, The 1970 Swiss computer scientist Niklaus Wirth also created Pascal language on the basis of ALGOL68. The former is designed for beginners of liberal arts students, easy to learn, is still amateur pet, the latter is a structural programming language model, beautiful structure, has been widely used in computer teaching, but they are limited in functionality, flexibility, efficiency is not high, and are not suitable for writing system programming.

Note: In 1991 and 2002, Microsoft's Alan Cooper and Paul Vick developed Visual Basic and Visual Basic. NET respectively. The 1983 Borland Company's Anders Hejlsberg and Philippe Kahn developed Turbo Pascal, 1985 Niklaus Wirth and Apple's Larry Tesler and created the object Pascal, 1995 Borland Company's Anders Hejlsberg and other people on the basis of the development of Delphi.

In 1970, Ken Thompson and Dennis Ritchie of At&t Bell Labs developed the UNIX operating system on the DEC's PDP-7 small Machine, which was originally written in assembly language. In order to make the UNIX operating system portable, a high-level language tool is urgently needed. To this end, (born in New York computer scientist) Dennis Ritchie based on B language, reference Algol68, in 1972 designed a C language. They rewrote the unix,1975 in C in 1973 and ported UNIX to PDP-11 using the C language.

2) features

C language is a portable system language, with sufficient control statements and data structure functions, including rich operators, so as to provide a strong ability to express, can be used in many different areas of application. But the C language is not for scientists and computer amateurs, but is designed specifically for programmers.

For efficient system programming, the C language provides powerful functionality and great flexibility. Compared with other advanced languages, C language is simple in syntax, free in expression and rich in library functions. If you compare programming to building a house, then the languages of Fortran and basic, like some prefabricated large precast pieces, are simple and quick to use, but with poor flexibility and limited functionality, only certain fixed-mode houses can be built; C language is like a block of small bricks, which is cumbersome to use, but flexible and And the function is infinite, can build a variety of buildings, but this requires C language programmers have a high level of professionalism.

Therefore, the C language assumes the user is the computer expert, takes the programmer responsibility system. It does not perform a complete type check, and there is no limit to the array's bounds. For efficient system programming, the C language also provides pointers and pointer operations, and programmers can manipulate all memory at will, arbitrarily modify any content.

The freedom of expression and the arbitrariness of operation also bring a lot of programming problems and security risks to C language. In particular, the C language ++/--operators and pointer operations, is much criticized.

Compared with other advanced languages, C language provides some low-level language features, more machine-oriented. Therefore, it is also known that C language is a intermediate language between high-level and low-level languages. 3) K&r C

For many years, the C language has no international standards, only one fact standard K&r C. It was not until 1989 and 1990 that ANSI C and ISO C (C89 or C90) were introduced respectively, and in 1999 ISO 2nd edition (C99) was introduced.

Unlike languages such as ALGOL, COBOL, and Ada, C is not a product of government departments or international organizations, but is an individual work. Although the C language performance is superior, used more and more widely, but in the first more than 10 years, the C language only "standard" is 1978 Brian Kemighan and Dennis Ritchie written "C Programming language" (the C programming Language) A book, usually referred to as K&r C or classic C.

The Appendix "C Reference Manual" (c Reference Manual) of the book becomes the Implementation Guide for C language, but the book lacks a description of the library function standard, which is generally the fact standard of the library function implemented by UNIX.

Description: Because C language syntax is simple, many basic functions (such as I/O statements) are implemented by library functions. Therefore, C language relies more on library functions than other advanced languages. 4) C89/C90 standard

ANSI (American National Standards Institute) established a X3J11 group in 1983 to proceed with the standardization of the C language. And finally in 1989, the introduction of ANSI C (ANSI x3.159-1989), 1990 years it has become the international standard ISO C (ISO/IEC 9899:1990 programming languages–c, programming language--c), formerly known as ANSI C or ISO C, which is now commonly referred to as C89 or C90.

The guiding principles of the standard are:

L believe in programmers;

L don't prevent programmers from doing what needs to be done;

• Keep language short and simple;

L provide only one way to perform an operation;

L make programs run faster, even if it's not portable. (does not pursue the definition of the abstract unity, more priority to operational efficiency)

These are actually the C language design intention, so ansi/iso of the C standard, the original C language modification is not much. The main changes of standard C to k&r C are the addition of function prototypes (prototype), the rigorous type checking of the input parameters of functions, and the addition of the standard function library of C language.

Type checking of a function prototype is a rigorous examination of the type of parameters that call a function's arguments and when the function is defined at compile time. The goal is to reduce the difficulty of program error correction (such problems are difficult to detect at runtime) while ensuring the security and stability of the operation (avoid overflow of the function call stack). (This also provides a condition for realizing the parametric polymorphism of C + + functions.) )

For example:

U k&r C: (OBSOLETE)

Power (); Forward Declaration of function

Power (x, N)//function definition

int x, n;

{

......

}

int p = Power (3) * Power (3.9, 5.4); Use (compilation may pass, Runtime generates logical errors)

U c89/c90: (recommended)

int power (int x, int n); //

Related Article

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.