Countryside Literacy C language Chapter 0

Source: Internet
Author: User

Recently, looking at some of the books related to Windows, I cannot help feeling that many of the difficulties experienced in the previous learning process are essentially a lack of basic knowledge, and there are few discussions and explanations on such basic knowledge in domestic Internet forums. Even if there are, most of the old posts from the plagiarism, there are many errors and outdated places. So I decided to write a systematic literacy article. The first short-term plan is about the C language. I assume that most of my readers should be on the go, or have just taken the "Advanced Language Programming (c)" Course for freshman, sophomore. I would like to briefly explain some basic concepts, common nouns. Then I'll use a few articles to explain some of the tools for programming C, and I'll focus on Microsoft's visual Studio 2017 and skip VC6.0 completely. Then there will be one or two articles explaining common compile-time errors and runtime errors, explaining how to check them, and how to debug a program. Finally, there may be several articles for readers who want to improve their level further. That's basically the way it is.

 0. What is C language

C language is a high-level programming language, the so-called high-level programming language, "in computer science,a high-level programming language are a programming language with strong Abstrac tion from the details of the computer "a high-level language is abstract and does not involve the language of computer hardware details. This makes the high-level language has two characteristics, one is through the abstraction to reduce the programmer needs to think about the scope, second, by changing the implementation on different platforms, so that the program can be written without modification on different platforms to run.

We are more concerned with the second feature, which means that the same HelloWorld program, whether on Linux or Windows, runs on AMD or Intel's CPUs, should print a "Hello World" on the screen. In the C language just born, this is actually an amazing progress, before that, programmers use assembly language to write programs, but the assembly language is entirely dependent on the machine you use, that is, you run on one machine, it is almost impossible to run on another computer using different hardware.

The busy programmer says that if you have a high-level language, you have a C language.

------- Genesis 1:3

  There are actually several kinds of 1.C languages

Here we have a little history.

In the late 1970s, Dennis Macalistair Ritchie and Kenneth Lane Thompson at Bell Labs designed and developed C language. However, in the years that followed, many companies and individual developers were not directly using the first version, but each changed the C language for ease of use.

in 1989, in order to avoid the differences in C language grammar produced by each development manufacturer, a complete set of international standard grammar, called ANSI C (also known as C89), was established by the American National Standards Bureau as the standard for C language. The 1980s to date the various program development tools (compilers, debuggers, text editors, etc.) generally support ANSI C. This is a widely accepted version, most textbooks and teachers in the domestic teaching are based on ANSI C.       

There are different versions of the C language, but only three are more important.

ANSI C (C89) This is one of the most widely accepted

C99 This version supports a lot of new syntax, many compilers also implement this standard (such as GCC), most of the time the use of C99 new features is no problem

C11 This version ... In fact, there is no compiler fully implemented, given the author's limited lifespan, no longer mentioned.

2.hello World, hello Assembly, hello CST

I think the readers have run a Hello World program, probably like this

  

#include <stdio.h>int  main () {    printf ("Hello world\n");     return0;}

You may have tried this program at a single step, hit a breakpoint on the third line, and then run it on line until the fifth line, the program ends.

However, your program is not as simple as you see it, it actually grows like this. (Part of source code is marked in bold)

1 #include <stdio.h>2  int  main () 3 {4 00007ff6b7ba0590 Push RBP5 00007ff6b7ba0592 Push Rdi6 00007ff6b7ba0593 Sub rsp,0e8h700007ff6b7ba059a Lea rbp,[rsp+20h]8 00007ff6b7ba059f mov rdi,rsp9 00007FF6B7BA05A2 mov ecx,3ahTen 00007FF6B7BA05A7 mov eax,0cccccccch One 00007FF6B7BA05AC Rep stos dword ptr [RDI] Aprintf"Hello world\n"); -00007ff6b7ba05ae Lea rcx,[string "Hello world\n"(07ff6b7bb03e8h)] - 00007ff6b7ba05b5 Call printf (07ff6b7b91528h) the      return 0;  - 00007ff6b7ba05ba xor Eax,eax - } -00007FF6B7BA05BC Lea rsp,[rbp+0c8h] + 00007ff6b7ba05c3 Pop Rdi - 00007ff6b7ba05c4 Pop RBP +00007FF6B7BA05C5 ret

How, isn't it as if you see Cthulhu, San value Kuangxiang?

This is actually HelloWorld in the VS2017, compiled by the Assembly code.

This code does three things,

One, save program context (contextual)

Second, call the printf function (14 rows)

Third, restore the program context (Contxet)

Some of the more intelligent readers may have come to understand immediately, raise their hands to answer that the code is compiled to convert the code into assembly code, assembly code can be easily converted to machine code, directly run. This idea is already quite close to the actual situation, but if the source code is simply translated, where are the 4-10-and 18-21-line programs coming from? This code is actually the compiler quietly plug in, without these extra work, the program is not running correctly, involving too many knowledge points, this article is no longer in depth. But in the next chapter I'll explain what the compiler did to your code, and how the IDE differs from the compiler.

  But more importantly, where does this printf function come from? We all know that in C, a function must be declared and defined somewhere before it can be called.

Input and output of the printf,scanf family (and sscanf,sprintf ...) is defined in stdio.h (Standard input/output),

Pow (), sqrt (), fabs (), which is concerned with mathematical operations, is defined in MATH.H

About Time () and other functions such as TM are defined in Time.h

These header files belong to the C language standard, and the file containing the implementation is called the C standard Library (c)

In the second chapter, we will focus on the relationship between Lib,dll,exe and other documents, explaining the role of the C standard library in our program.

This is just a description of the open pit, so it's over.

Dear readers, see you next year , Ah no, see you next week.

  

Countryside Literacy C language Chapter 0

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.