C language basics - understanding C language

Table of contents

1.1: History of C language

        1.1.1: Origin

        1.1.2: Standardization

1.2: Advantages and disadvantages of C language

        1.2.1: Advantages of C language

        1.2.2: Disadvantages of C language

        1.2.3: Use C language efficiently


1.1: History of C language

        1.1.1: Origin

The C language was a by-product of the development of the Unix operating system         at Bell Labs by Ken Thompson , Dennis Ritchie and other colleagues.

        1.1.2: Standardization

        K&R: In the 1970s, the C language continued to develop, and in 1978, the work "The C Programming Language" co-edited by Brian Kernighan and Dennis Ritchie was published. This book quickly became a manual for C programmers as soon as it was published. And because there was no formal standard for the C language at the time, this book became the de facto standard.

        ANSI C (Standard C): In 1983, the American National Standards Institute (ANSI) began to compile the C language standard. After multiple revisions, it was completed in 1988 and officially adopted in December 1989. The International Organization for Standardization (ISO) adopted this standard in 1990.

1.2: Advantages and disadvantages of C language

        1.2.1: Advantages of C language

  • Efficiency: This is one of the inherent advantages of the C language. Since the C language was originally used to write assembly programs, it is particularly important to run them quickly and occupy limited memory.
  • Portability: C language has good portability. Under different operating systems, cross-platform program development can be carried out with simple modifications or no modifications.
  • Powerful: C language has a huge set of data types and operators, which makes C language powerful in expression.
  • Flexibility: C language is eclectic in grammar, creating and compounding on the basis of the original grammar, giving programmers more room to play.
  • Standard library: One of the outstanding advantages of the C language is the standard library, which contains hundreds of functions for input\output, string processing, storage allocation and other operations.
  • Integration with Unix systems: The C language is particularly powerful in integrating with Unix systems. In fact, some Unix tools even assume that the user knows C.

        1.2.2: Disadvantages of C language

  • C can be buggy: C's flexibility makes it a buggy language. Many programming errors that can be found in other languages ​​cannot be detected by the C compiler. In this respect, C is very similar to assembly language in that assembly language cannot detect most errors until the program is running. To make matters worse, C language also contains a lot of hidden dangers that are not easy to detect.
  • C can be difficult to understand: although C is a small language by most measures, it also has many features that other general-purpose languages ​​do not have (and are often misunderstood). These features can be combined in many ways, some of which may be obvious to programmers but difficult for others to understand. Another problem is the concise nature of C programs.
  • C programs can be difficult to modify: When large-scale programs are written in C, if maintenance is not considered in the design, it will be difficult to modify. Modern programming languages ​​usually provide a language feature called "module" ("unit" or "package"), which can break a large-scale program into many manageable chunks. Unfortunately, C language lacks exactly this feature.

        1.2.3: Use C language efficiently

  • Learn how to avoid the pitfalls of C language: You can refer to Andrew Koenig's book "C Pitfalls and Pitfalls". Modern compilers will detect common defects and issue warnings, but no compiler can detect all defects.
  • Leverage existing code bases: It's a benefit that everyone is using C, and it's a very good idea to use code written by others into your own programs. C code is often packaged into libraries (collections of functions). Obtaining the appropriate libraries can both greatly reduce errors and save considerable programming effort.
  • Adopt a realistic set of coding conventions: A coding convention is a set of design guidelines that programmers must follow even if the language itself does not mandate them. Proper specifications can make programs more uniform and easier to read and modify. Using any programming language requires specification, especially C language. As mentioned earlier, the C language itself has a high degree of flexibility, which makes the code written by programmers difficult to understand.
  • Use Standard C, less Classic C: Standard C is much more than just a better form of Classic C. Standard C adds many features that allow the compiler to check for errors, but Classic C ignores this issue. 
  • Avoid non-portability: Most C compilers provide features and library functions that are not part of standard C. It is best to avoid using these features and library functions unless absolutely necessary.

Guess you like

Origin blog.csdn.net/m0_74436212/article/details/131216144