C Language (i): initial C language

Source: Internet
Author: User

Study notes:

    • history and characteristics of C
    • Steps to write a program
    • Some knowledge of compilers and linker
    • Standard of C

The origin of 1.1 C language

in 1972, Dennis Ritchie (Dennis Ritch) and Ken Thomson (Ken Thompson) at Bell Labs in the United States invented the C language when developing the UNIX operating system. However, in the design of C language It is not an independent thinking design, it is based on the basis of B language design, as for the origin of B language, can refer to the origin of B language, C language is designed to give programmers a programming tool to use, Its main goal is to become a useful language.

 1.2 Reasons to choose C language Programming

  In the past 40 years, C has become one of the most popular and most important programming languages, in the top 10 most popular programming language rankings, often with the Java language in the first second ranking scramble, not the first is the second, its growth is mainly summed up in the use of it people are very satisfied with the language, the past 20 years, While many people are moving from C to other programming languages (such as C+ + objective-c Java ), C language still stands out in many languages by virtue of its own strength.

1.3 Characteristics of C language (advantages)

  • C language is a popular language, incorporating the control characteristics of computer science theory and practice. The C language design concept allows users to easily complete top-down planning, structured programming, and modular design. As a result, programs written in C are easier to understand and more reliable.
  • C language is an efficient language, in the design, it fully utilize the advantages of the current computer, so the C language Program design more compact, and run fast, in fact, C language has a fine-tuning control capability that is usually in assembly language (assembly language is a series of internal instructions designed for a special central processing unit, using mnemonic notation; different CPU families use different assembly languages.
  • C is a portable language, which means that a C language program written in one operating system can run in other operating systems with little or no modification; For example, you have designed a HelloWorld C program with VC or VS in the Windows operating system, You can also put it on Linux or Unix system to execute, and will not error, however, some programs just need to change the main program header file a little, most languages want to become portable language, C language is the leader of the portability language.
  • The C language is powerful and flexible (these two nouns are often used in the field of computers or hacking or infiltration), for example: powerful and flexible UNIX systems, most of which are written in C, and other languages such asFORTRAN,Perl, Most of the interpreters and compilers inside Python,Pascal,LISP,Logo,BASIC) are written in C. Therefore, when using Fortran in UNIX, the final executable program is generated by the C program. The C language can be used to solve problems in physics and engineering, and even to write special effects for films.
  • C language is designed to meet the requirements of programmers, programmers can use C language to access computer hardware, manipulating memory bits. The C language has a rich array of operators that allow programmers to quickly profile their intentions. C language, although not Pascal rigorous, but more than the limitations of C + +, such flexibility is the advantages and disadvantages. The advantage is that many tasks are handled in C with special brevity (e.g., format for converting data); The downside is that you may make some inexplicable mistakes that are unlikely to occur in other languages. C language provides more freedom, but also allows users to assume greater responsibility, in addition, C language has a lot of functions from the library, you need to use the # include main function to call to let the function run.

the application scope of 1.4 C language

  • Most of the company's internal programming uses C language
  • The development of the operating system is also basically using the C language
  • Programming language development (Python language is the C language design)
  • Graphical program development (C language development of graphical programs more efficient and fast)
  • Ai Design (AI is mostly used in assembly or C language)
  • Automotive Safety Design (internal program is basically written in C language)
  • Linux kernel (written in C language)
  • Unix operating system (written in C language)
  • The Windows operating system (written in C, most of which appears to be written in C + + or assembly language, but a few are written in C)
  • Computer game development
  • PC-Side Applications
  • Robot Factory
  • Star Wars movie effects
  • Embedded system development
  • Lucas Corp.

1.5 How computers work

The modern microcomputer mainly consists of a variety of internal architectures: the central processing Unit (CPU) undertakes most of the computational work. Random storage Memory (RAM) is the workspace where programs and files are stored, whereas permanent memory storage devices (which used to refer to some mechanical hard drives and now include SSDs such as SSDs) will not be lost after the computer is turned off, and there are also peripherals (keyboard, mouse, touch screen, Monitor) provides the interaction between a person and a computer. The CPU is primarily responsible for processing programs.

The CPU's work is very simple, it gets and executes an instruction from memory, then gets and executes the next instruction from memory, and so on (a GHz CPU can repeat this operation for about 1 billion times a second, so the CPU can repeat the tedious work at an alarming rate, The CPU has its own workspace-consisting of a number of registers, each of which can store a number. A register stores the memory address of the next instruction, and the CPU uses that address to obtain and update the next instruction. After obtaining the instruction, the CPU stores the instruction in another register and updates the address of the first register to store the next instruction. The CPU can understand a limited number of instructions (the set of these instructions is called the instruction set . Moreover, these instructions are quite specific, and many of these instructions are used to request the computer to move a number from one location to another.

All content stored on the computer is a number. Computers store numbers and characters in numbers, such as characters that are used in text documents. Each character has a numeric code. The instructions for the computer-loaded registers are also stored digitally, with each instruction set having a digital code (i.e., machine language) to represent it.

In short, the computer works: If you want the computer to do something, you have to give it a special list of instructions (the program), tell the computer exactly what to do and how to do it, and you have to create the program in a language (machine language) that the computer can understand directly. This is a tedious, tedious, laborious task. To accomplish something as simple as adding two numbers, a computer needs to be categorized into steps similar to the following.

    • Copy a number from memory location 2000 to register 1
    • Copy another number from memory location 2004 to register 2
    • Add the contents of register 2 to the contents of register 1 and send the result in register 1
    • Copy the contents of register 1 to memory location 2008

1.6 Advanced computer languages and compilers

  High-level programming languages (such as: C) simplify programming in many ways, starting with the need not to use a digital code to denote instructions, or to take into account the specific steps the CPU needs to complete a task.

Total = Mine +yours;

We use the above variables for example, just to look at this example to know what the programming language wants to do, and if it is written in machine language equivalent instruction (many of the instructions in the form of digital code) is much more laborious. But the opposite is the case for computer language. In the computer's view, high-level instructions are a bunch of incomprehensible useless data. So, the compiler comes in handy here. The compiler's role is to translate high-level language program instructions into a machine-language instruction set (binary) that can be understood within the computer, and the programmer carries out high-level thinking activities, while the compiler handles tedious and tedious detail work.

1.7 Language standards

   at the beginning of the development of C language, there was no so-called C language standard, in 1978, Blaine Collingham (Brian Kernighan) and Dennis Ritchie (Dennis Ritchie) co-authored The C programming Language(C language Programming) First Edition is recognized as the C standard, commonly referred to as K&RC or classic C. Unlike most languages, C is more dependent on libraries than other languages and therefore requires a standard library, in fact, because of the lack of official standards, the libraries provided by UNIX implementations have become standard libraries.

Some standards of 1.8 C language

    • Ansi/iso C Standard
    • C99 Standard
    • C11 Standard

    1.9 7 steps to using the C language

    • Define the target of the program
    • Design program
    • Writing code
    • Compile
    • Run the program
    • Testing and debugging Programs
    • Maintain and modify programs

2.0 Programming mechanisms

generating program The body process varies by computer environment. C is a portable language that can be used in many environments, including: Unix , Linux , MS-DOS (some are still in use), Windows and Macintosh OS, some products evolve or replace over time, and when you write a program in C, the content is stored in a text file. The file is referred to as the source code file. Most c systems, including those previously mentioned, require the end of. C (for example: Wordcount.c and HELLO.C), in the file, preceded by the dot is called the base name (basename), and the dot followed by the extension (extension). Therefore, the file name should meet the specific requirements of a particular computer operating system, such as: In the MS-DOS environment is older, it requires the base name must not exceed 8 characters. Therefore, the wordcount mentioned earlier is an invalid DOS file name; some UNIX systems allow longer file extensions of up to 14 characters, while some UNIX systems allow longer file names, up to 255 characters, Linux, Both Windows and Macintosh OS are allowed to use long filenames.

The basic strategy of C programming is to use the program to convert the source code files into executable files , the typical C implementation by compiling and linking two steps to complete the process. The compiler converts the source code into intermediate code, and the linker merges the intermediate code with other code to generate the executable file. C Use this divide-and-conquer method to facilitate the modularization of the program, you can independently compile the module, and then use the linker to merge the compiled module, in this way, if you only change a module, you do not have to recompile other modules, in addition, the linker will also write your program and precompiled library code merge.

In short, both the target code and the executable are made up of machine language directives . However, the target file contains only the machine language code that the compiler has written for you to translate, and the executable file also contains the machine code for the library functions and startup code used in the program you wrote.

C Language (i): initial C language

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.