Fundamentals of C language programming under Linux

Source: Internet
Author: User

Linux under C language Programming Fundamentals 2. Vim

Vim is a very good text editor and many professional programmers use vim to edit code

Then you can take this picture as a computer desktop background, learning one or two keys every day:

The programmer has several key hints:

    • The uppercase "K" can be used to find help for the function: Look at the man page, in command mode, place the cursor on the function name, press "K" to see the mans page directly.
    • Several settings

: Set NU Displays line number

: Set AI automatically indents rows

: Set ts=4 sets a TAB key equal to several spaces

    • Move cursor

[[Go to Previous ' {' in first column]

]] to go to the next "{" In the first column

{Go to previous empty row

} go to the next empty line

3. GCC

    • GNU CC (referred to as GCC) is an ANSI C-compliant compilation system in the GNU project that compiles programs written in languages such as C, C + +, and object C. GCC is also a cross-platform compiler that can develop software on the current CPU platform for a variety of hardware platforms of different architectures, so it is especially suitable for development in the embedded domain.

We can divide the compilation process into four steps to compile hello.c to generate executable Hello as an example, such as:

    • Preprocessing: Gcc–e hello.c–o hello.i;gcc–e Call CPP
    • Compilation: Gcc–s hello.i–o hello.s;gcc–s Call CCL
    • Compilation: Gcc–c hello.s–o hello.o;gcc-c Call as
    • Link: gcc hello.o–o hello; gcc-o call ld

The compilation process is difficult to remember, we simplify, the first three steps, GCC parameters linked to "ESc", the corresponding input file suffix is "ISO", so memory is much easier.

Another important point to learn about GCC is: reference materials, "in-depth understanding of computer systems" 7.6, 7.10, learning Static library, the production of dynamic library.

4. gdb

Recommended to use CGDB, better than GDB, familiar with the VC debugging methods, you can use DDD. Note Use GCC to compile with the "-G" parameter. Refer to the GDB Reference Card GDB's most basic commands are:

    • GdB Programm (Start gdb)
    • B Set Breakpoints (4 breakpoints are set: Line breakpoint, function breakpoint, conditional breakpoint, temporary breakpoint)
    • Run starts running the program
    • BT Print function Call stack
    • P View variable values
    • C continue running from the current breakpoint to the next breakpoint
    • N Single Step operation
    • S Single Step operation
    • Quit Quit GDB

Problem: GDB's n (next) command lets GDB execute the next line and then pause. The s (step) command acts like this, except that the step command enters the function when the function is called, so what should be preferred in actual use? Why?

A few other debug commands that I think should be mastered are:

    • Change of display tracking variable value
    • Until jump out of the loop
    • Finish Jump function
    • Help
Main content:

Fundamentals of C language programming under Linux

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.