C Language Development in linux and linuxC Language Development

Source: Internet
Author: User

C Language Development in linux and linuxC Language Development

In the eyes of many people, C language and linux are often inseparable. There are many reasons for this. The most important part is that linux itself is an outstanding work of C language. Of course, the linux operating system supports C language quite well. As a real programmer, if a complete program has not been written in C language under linux, he can only say that his understanding of the C language itself is superficial, the system itself is not well understood. As a programmer, the linux system provides us with many ideal environments, including the following aspects,

(1) A complete compilation environment, including gcc, as, ld, and other compilation and link tools
(2) Powerful debugging environment, mainly gdb tools
(3) rich automatic compilation tools, mainly make tools
(4) Diversified OS options, such as ubuntu and redflag
(5) vast open-source code library

Of course, no matter what I say, my friends should be brave enough to take the first step forward. If you have no Linux programming experience, you can first install a virtual machine on your pc, and then write your own C language code under shell. Http://hovertree.com/menu/c/

# Include <stdio. h> int main () {printf ("hello! \ N "); return 1;}/* He asked hovertree.com */

After writing the above Code, you need to do two steps: 1. Input gcc hello. c-o hello; 2. Input./hello. If everything works, you will see a line of hello printing on the screen. If you see it, congratulations! You can start your linux C Programming journey.

Of course, we will not be satisfied with such a simple printing function. Below we can write a simple iterative function,

# Include <stdio. h> int iterate (int value) {if (1 = value) return 1; return iterate (value-1) + value;} int main () {printf ("% d \ n", iterate (10); return 1;}/* Ask hovertree.com */

In this case, repeat the preceding steps: 1. Input gcc hello. c-o hello; 2. Input./hello. Of course, if everything is OK, you will see the output of 55 on the screen. Originally, the sum of data from 1 to 10 is 55, which indicates that our program is correct.

Of course, there will be some friends interested in program disassembly, so he needs two steps: 1. gcc hello. c-g-o hello; 2. objdump-S-d. /hello. The reason for adding-g during gcc compilation is to add debugging information. The-S option in objdump is to display the original C language source code while displaying the assembly code.

int iterate(int value)  {   8048374:       55                      push   %ebp   8048375:       89 e5                   mov    %esp,%ebp   8048377:       83 ec 08                sub    $0x8,%esp      if(1 == value)   804837a:       83 7d 08 01             cmpl   $0x1,0x8(%ebp)   804837e:       75 09                   jne    8048389 <iterate+0x15>          return 1;   8048380:       c7 45 fc 01 00 00 00    movl   $0x1,0xfffffffc(%ebp)   8048387:       eb 16                   jmp    804839f <iterate+0x2b>      return iterate(value -1) + value;   8048389:       8b 45 08                mov    0x8(%ebp),%eax   804838c:       83 e8 01                sub    $0x1,%eax   804838f:       89 04 24                mov    %eax,(%esp)   8048392:       e8 dd ff ff ff          call   8048374 <iterate>   8048397:       8b 55 08                mov    0x8(%ebp),%edx   804839a:       01 c2                   add    %eax,%edx   804839c:       89 55 fc                mov    %edx,0xfffffffc(%ebp)   804839f:       8b 45 fc                mov    0xfffffffc(%ebp),%eax  }   80483a2:       c9                      leave   80483a3:       c3                      ret  

Recommended: http://www.cnblogs.com/roucheng/p/cbianyi.html

 

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.