Some questions for php programmers to learn c

Source: Internet
Author: User
Tags amd processors
1. php has a zend engine to compile php. What about c? Is the operating system compiling him? 2. Many years ago, I knew that computers only knew 01 code, but today I thought that the computer only knew 01, and I understood that cpu only knew 01, right? 3. What is the relationship between c and the operating system? For example, I... 1. php has a zend engine to compile php. What about c? Is the operating system compiling him?
2. Many years ago, I knew that computers only knew 01 code, but today I thought that the computer only knew 01, and I understood that cpu only knew 01, right?
3. What is the relationship between c and the operating system? For example, can I use c-compiled files in windows in linux? I don't think so. Is that the same code? If I want to use it in linux, therefore, you must copy the copy to linux for compilation.
4. I found that I have used a lot of things and I feel that I am actually using other people's things. No matter how js or php or html is learned, what is the underlying layer of people, I don't know how he interacts with the entire computer at a deeper level. After learning c, I feel more like a cainiao.

I am a cainiao and have asked a lot of questions, but I really don't know. Thank you, segmentfault.

Reply content:

1. php has a zend engine to compile php. What about c? Is the operating system compiling him?
2. Many years ago, I knew that computers only knew 01 code, but today I thought that the computer only knew 01, and I understood that cpu only knew 01, right?
3. What is the relationship between c and the operating system? For example, can I use c-compiled files in windows in linux? I don't think so. Is that the same code? If I want to use it in linux, therefore, you must copy the copy to linux for compilation.
4. I found that I have used a lot of things and I feel that I am actually using other people's things. No matter how js or php or html is learned, what is the underlying layer of people, I don't know how he interacts with the entire computer at a deeper level. After learning c, I feel more like a cainiao.

I am a cainiao and have asked a lot of questions, but I really don't know. Thank you, segmentfault.

You have asked a lot about the computer architecture. In fact, you do not need to know so much about the C language, but you are a curious person and have clear logic thinking.
01 This is not a software concern, but a hardware concern. In digital logic, we call it high and low levels. The current goes through a component. If the voltage is high voltage, it is recorded as 0, and the low voltage is recorded as 1. After a logic is computed and combined with the features of components, we can express this logical operation through the combination of components. At the beginning, it must have been a simple diode or something like that. Now you have seen the cpu, and the transistor in it is as small as nano computing. Computing tasks in the computer are finally handed over to the cpu. Of course, a casual command on the upper operating system does not know the cpu. A command in the operating system must be split into several commands, when each command is implemented, it is allocated to different circuit units for processing. The processing process of these commands is actually a series of 01 operations in the circuit. These commands (all composed of Binary Code) are the legendary machine code. Because the machine code is too difficult for people to read, the predecessors converted it into an assembly language, the development speed and learning cost of assembly language are still not ideal, so it is the birth of advanced language.
In fact, the C language will eventually be converted into machine code. For exampleint a = 1;During compilation, the compilation is first translated into several compilations, and then converted into machine code. Therefore, to put it bluntly, compiling is the process of converting c into assembly and then machine code. The executable program generated after compilation can happily send commands to the cpu.
Php is a parsing language and does not need to be directly compiled into executable programs. Its code is parsed using the zend engine. The zend engine can be understood as an executable program. When it knows what you want through lexical and Syntax Parsing, it directly calls a built-in function of the program to give you a processing result.
As for the incompatibility between the linux program and the windows program, the reason is that the binary format of the executable program generated by the operating system is different, and the operating system does not recognize each other.
The key to c language learning is to understand the syntax. First, you should learn how to use it. We recommend that you read "c expert programming" and "c and pointer".

  1. Gcc vc clang icc is a C language compiler.

  2. Yes. The cpu only recognizes the machine code, and the mnemonic is an abstraction invented by humans to facilitate compilation.

  3. Most operating systems are written in c. Although both windows and linux run x86 programs, they are not directly compatible with different executable file formats. It seems that application-level virtual machines can achieve this.

  4. The interpreter for js, php, py, and other scripting languages is implemented in c. The c language is responsible for dealing with the system. Part of the library of the scripting language calls the system api to deal with the system. When learning c, you should focus on the underlying interaction. When learning other advanced languages, you should focus on the business logic.

This is probably not a science class, buddy. If you have questions about computer principles, you will soon understand them.
Here is a rough introduction. The computer system itself is an abstract process.

  1. The bottom layer is, of courseTransistor circuitThrough circuit abstraction into various digital logic, we can implement arithmetic operations (such as addition and subtraction), logical operations (Transfer replication) and other operations.

  2. ThenCommand System, RefersMachine commands(The abstract of the previous pair of circuits is called "micro-Instruction"). It is also an abstraction that encapsulates the basic functions of a logical circuit into addition, subtraction, multiplication, division, floating point operations, string processing, and so on. The so-called "machine language" is a string of command code.

  3. ThenAssembly LanguageBecause 0101 is meaningless to people, it is a codenamed assembly language, suchADD(Plus) Representative001In this way, a small abstraction has semantics. The program written in assembly language is then translated into the original binary machine language.

  4. FinallyAdvanced LanguageFor example, C, because the abstract level of the assembly language is too low, it is still very difficult to appear in advanced languages. The C language is closer to the natural language. C needs to be compiled (this is the role of the compiler). When there is no OS (operating system), it is also translated into a machine language. When there is an operating system, because the OS needs to determine how to use this program, the compiled executable file is not just a machine command, but also has a certain format, such as adding a file header. The formats required by different OS are different.

    Here we can answer LZ's question: why can't the compiled executable file be cross-platform? (a question can be answered after a while)

    The hardware for the first program, such as the cpu, may be different, but the commands for different hardware may be different. The machine languages required are also different. The formats of executable file programs compiled by the second and different operating systems are different, other operating systems do not recognize the second OS. Different Operating System APIs are often called.

    I don't want to write anything, but it's very simple. Many important points are omitted. Let's take a look at it. It's also a review of my previous knowledge.

Php programmers have to define this.

Programmer: Good Computer Foundation, good understanding of compilation principles, understanding how a language is compiled into a target code. Graphics, basic knowledge of matrix changes, vectors, ouarla angles, and Quaternary elements.

Php: you are more interested in the PHP language based on the programmer. You can understand the compilation method of this language based on the Compilation Principle. understand why PHP runs in fastcgi mode can shorten your coding lifecycle and minimize the business logic of programming.

Do you think you are a PHP programmer?

1. gcc compiler
2. Yes. It used to be an electronic tube. The transistor and ultra-large-scale circuit integration have already been used in more than 10 million projects.
3. No. The linux and windows kernels are completely different. You can run them in linux using other methods.
4. Learning is like this. The more you investigate, the more underlying the program. Just like when you learn other advanced programming languages, you will find that C is more underlying and you can operate on pointers, after learning C, you will find that the Assembly is more underlying. You will find that it is difficult to use it. Of course, there is another bottom layer. I heard my teacher say that he has learned the compilation and used the drilling technology. I have never touched on it, however, I know that the source code of the assembler program is written in a special paper bag, and I have not tried to debug this statement. I only rely on myself, and I can use the sticker to paste out the hole, but this is basically used for mis-hitting or error. It is basically difficult to correct the program error. Then, according to the mechanical code corresponding to each line of the Code, it seems that there is no hole as 0 and no hole as 1.
If you want to learn the underlying layer, you must first stand for the programmer's position. From the programmer's perspective, you will find that you have access to another discipline. If you want to simply understand and involve the underlying layer, you can also play with embedded systems. Embedded systems are also popular nowadays, and smart home is the product.

1. gcc, clang, and other compilers
2. Only 1 and 0 for any hardware part of the computer
3. c is a programming language, and the operating system is a set of programs written in a programming language. Including memory management, task scheduling, disk management, and system calling. Effectively manage the hardware and abstract it into a unified set of API calls. Programs between systems are not universal because the system calls they apply are different. The implementation of a printf function in C libraries on different platforms must be different.

  1. C library packaging also hides a lot of underlying details, and the compiler also helps us do a lot. For example, the main function will be related to some program running functions by default, and the ELF/PE format of the application is encapsulated. After learning the x86 assembly, it means there is actually a lower layer of XD below the underlying layer.

See Understanding Computer Systems

It is recommended that the subject publish "C Primer Plus" on the Internet. You can answer most of your questions by looking at Chapter 1 Overview.

The formats of binary executable files vary with operating systems. For example, ELF and PE are used in Linux. For example, you can usereadelf -a /bin/catView the ELF information of the program cat. For example, you can see the entry point address of the program 0x402602, and the shared library that the program depends on.

The Linux executable program is to create a memory Layout Based on the ELF information of the binary executable file, suchcat /proc/self/mapsView cat loading table (memory layout ):

00400000-0040b000 r-xp 00000000 4198651/bin/cat (text Segment) 0060a000-0060b000 r -- p limit a000 08:06 4198651/bin/cat (data segment) 0060b000-0060c000 rw-p rjb000 08:06 4198651/bin/cat (bss segment) 016be000-016df000 rw-p 00000000 00:00 0 [heap] (each shared library address on which the program depends is omitted below) 7fff31d00000-7fff31d21000 rw-p 00000000 0 [stack] (vdso and vsyscall are omitted below)

The text segment (code segment) stores the Program Execution Code contained in the ELF file, that is, the machine instruction of the CPU.
After the memory layout is created, jump to the first machine instruction of the program and start execution.

Machine commands contained in binary files generated by different compilers (such as GCC, Clang/LLVM) on the same machine and operating system of the same C code segment, not necessarily the same, because different compilers may have different optimization implementations. For example, the Intel compiler ICC Compilation Program does not support AMD processors in the same x86 architecture, it should be that Intel uses its own unique CPU features.

On the same machine, the machine commands included in binary files compiled by different operating systems may be more different, although these machine commands can be identified and executed by the current machine (CPU.

Different CPU architectures have different instruction sets, and the commands on other machines are naturally different. Therefore, binary programs on x86 cannot run directly on ARM, however, you can use a cross-compiler such as arm-none-linux-gnueabi or Android NDK to generate an ARM binary file (machine code) on Linux x86 ).

For PHP, the code we write is handed over to the Zend Engine for running, rather than directly to the CPU for running. Therefore, as long as Zend Engine is guaranteed to be cross-platform, our PHP code can be cross-platform. PHP opcode is for Zend Engine and similar to machine code for CPU. We can use PECL to expand vld to view the opcode of the PHP program.

I'm not from a science class, but I understand it.
For example, to build a house, we use bricks, cement, steel bars, etc. Different houses use different materials, such as wood, to build a house. This is like writing a program in advanced languages. It can be implemented in different languages. However, bricks, cement, steel bars and other materials are made by others. If we want to make all the materials ourselves, it is almost impossible. The bottom layer is how to make these basic materials, for construction workers, we need to understand the characteristics of these materials so that we can organically build the most ideal building, and we need to focus on our construction process itself, as for materials, you can give them to those who specialize in research so that everyone can exert their own strength, as can programmers.

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.