BBS Shuimu Tsinghua Station: Essence
Sender: kongming (no night ...), letter area: Linux
Title: RE: How to learn Linux?
Sending station: BBS Shuimu Tsinghua Station (MON AUG 2 11:27:04 1999)
I posted an article for you, briefly introduced the programming tool under Linux,
Getting start is no problem.
This is some of my recently prepared books.
Strictly declare:
This article has a proprietary copyright of Kongming netizens.
All rights reserved, unauthorized, not allowed to copy, adapt or change to adapt, spread.
Mainly include the following:
? GNU C, C compiler
? GNU Make Tool
? GNU debugger
? RCS version control system
And briefly introduce the PERL scripting language that is widely popular on the Linux system.
Contrast two different coding styles of Linux and Windows NT.
Look at the bbs, take a little, take a look at home.
Chapter 13 Software Development
Since the operating system is just a tool, for most readers, the ultimate goal of learning the operating system is to use the operation.
The application software on the system completes its own work or use the development tool to develop applications. Therefore, for one
For the system, the development tools can be obtained, as well as if these development tools are effective, becoming a evaluation operating system.
An important factor.
The last three chapters of this section will mainly compare Linux and Windows NT from the perspective of developers. This chapter is mainly
The content is as follows:
? Introduce the operating system to serve the various system services provided by the developer;
? Introduce the main development tools on the operating system.
Considering that many readers may have a lot of development tools on Linux, this chapter will introduce some Linux.
Used development tools. Of course, software development is not a chapter of the district, and more needs readers.
Going yourself to practice.
13.1 POSIX standard and operating system interface
13.1.1 Linux and Windows NT support for POSIX standards
From the first chapter, we know that POSIX is a standard that mainly defines the system call interface of the operating system.
The POSIX standard was originally developed to improve the portability between UNIX systems. Linux is a POSIX compatible system.
The POSIX subsystem is included in Windows NT. But what is the difference between the POSIX of these two operating systems?
POSIX is composed of a very complex standard system, which is widely accepted POSIX standards in POSIX.1 standard.
quasi. POSIX.1 is a source code-level compatibility criteria that provides an operating system C language programming interface, content
Recommend POSIX.1A (System Interface Extension), POSIX.1B (Real Time), POSIX.1C (Thread), POSIX.1D (Real
Time expansion), POSIX.1E (security), POSIX.1F (transparent file access), POSIX.1g (unrelated service)
And POSIX.1H (fault tolerant), etc. Another important criterion for POSIX is the POSIX.2 standard, which defines the operation
System's shell and tool standards. The POSIX standards that are usually talked are the two standards. Linux supports complete
POSIX.1 and POSIX.2 standards; and Windows NT only provides support for POSIX.1, and it is incomplete
The whole system, many aspects (such as I / O) require Win32 API to complete. In fact, many POSIX.1 interfaces of Windows NT are indirectly implemented by Win32 API.
The POSIX.1 version in Windows NT basically doesn't use it, in Visual Studio 6.0,
Even support for POSIX.1. If the reader wants to make some POSIX developers on Windows NT
Do not use Windows NT Posxi.1. Users can use third-party POSIX systems, or by GNU
GNU Win32 tool. These products offer more powerful features, such as Software System Inc.
POSIX.2 Toolbox (OpenNT) has the following characteristics: real UNIX shell, and in Windows NT
The ability to run x window, etc. These software adds to the non-complete POSIX.1 system of Windows NT as follows
characteristic:
POSIX.1, POSIX.2 and ANSI C interface;
• Use on Intel and Alpha platforms;
? BSD socket support;
• SYSTEM V shared memory and signal IPC mechanism;
• X11R5 client, library and head file;
? OpenNTIF (OSF / MOTIF 1.2.4 window manager and development library);
? Color Curses library;
• Complete shell job management;
? Tape equipment support;
Unix Development Tools: make, RCS, YACC, LEX, CC, C89, NM, AR, Strip, etc.
GNU Win32 is a GNU development tool for X86 and PowerPC's Windows NT / 95. Use
The application developed by development tools can access the Microsoft Win32 API, and can also access the Cygwin32 API, it
Additional features similar to Unix, including UNIX sockets and process controls. Use these tools to increase
POSIX subsystem on strong Windows NT:
• Write the Win32 console or by using standard Microsoft Win32 API or / and CYGWIN32 API or
GUI application;
• It is convenient to configure and establish many GNU tools from the source code, including GNU Win32 Development Tools
itself;
? Many important UNIX tools can be transplanted to Windows NT without having to make a large-scale repair on the source code.
change;
• Contains a fairly complete UNIX environment, you can use many normal UNIX system tools.
With the above two software, readers can access the following sites:
http://www.softway.com/opennt/homet.htm
htt: //www.cygus.com/misc/gnu.win32
Contrary to Windows NT, Linux is a fully compatible system for POSIX.1 standards. LINUX
The POSIX.2 standard implementation is provided by the GNU tool and a library, where the most important C-function library is GLIBC.
The library contains the following:
? ISO C: C: C: The international standard of programming language. GNU C Function Library and US National Standards Bureau (ANSI) announced
The C standard is compatible. This standard was later received by the International Standardization Organization (ISO / IEC 9899: 1990).
? POSIX: ISO / IEC 9945 (ie IEEE 1003) standard for operating system. The GNU C function library implements ISO / IEC 9945-1: 1996 (POSIX System App Programming Interface, Posix.1) specified
All functions. This standard is an extension of ISO C, including file system interface primitive, and device-related end.
End control functions and process control functions. At the same time, the GUN C function library also supports part by ISO / IEC
9945-2: 1993 (POSIX Shell and Tool Standard, Posix.2) Specified functions, including
Encloses functions for processing regular expressions and patterns.
Berkeley UNIX: BSD and SunOS. The GNU C function library defines that some UNIX version has not been marked
The function of quarantine, especially 4.2 BSD, 4.3 BSD, 4.4 BSD UNIX system (ie "Berkeley Unix")
And "Sunos" (Volkswage 4.2 BSD variants, including some UNIX SYSTEM V "
can). The BSD function includes symbolic link, SELECT function, BSD signal processing function, and socket, etc.
Wait.
• SVID: SYSTEM V interface description. SYSTEM V Interface Description (SVID) is description of AT & T UNIX SYSTEM
V Operating system documentation, it is an extension superchard for POSIX standards. GNU C function library defines most
The number is specified by SvID without the function specified by the ISO C and POSIX standards. From System v
Support functions include inter-process communication and shared memory, HSearch and Drand48 Functions, FMTMSG
And some mathematical functions.
XPG: X / Open Primary Guide. X / Open Portable Guide (by x / open company, ltd.
Publishing) is a more general standard than POSIX. X / Open has UNIX copyright, and XPG
Specifies the need to be a UNIX operating system that must meet. GNU C function library follows X / OPEN portable
Sexual Guide (Issue 4.2) and all XSI (X / Open system interface) to expand,
Also follow all X / Open UNIX extensions.
At the same time, Linux also contains many functions libraries with many character interface management, network protocol processing, and graphic image processing.
These function libraries are issued as part of the general Linux business distribution. Details related to these functions
Introduction, readers can refer to Appendix C.
In fact, Microsoft does not intend to make your own operating system to be fully compatible with UNIX, if the reader looks
"Microsoft SQL Server 6.5 Technical Reference" edited by Microsoft (China) Co., Ltd. (Science Publishing
The Society, the Longmen Site published in 1997, you can understand the fierce competition of Microsoft and UNIX camps. since
Microsoft speaks in this book how UNIX is bad, of course, will not have any POSIX from UNIX?
Good support.
So what about the operating system interface of Windows NT?
13.1.2 Operating System Interface for Windows NT
Windows NT's operating system services are mainly reflected in the Win32 API, which can be divided into the following categories:
? Window management. Applications can be used to create and manage the part of the window, involving windows, messages, messages
Queue, Control, Dialog, Mouse and Keyboard Enter, Timer, Menu, Keyboard Accelerator, and Other
Content related to window management. • Graphics device interface. The application is used to implement the part of the device-independent graph, involving the device description table,
Coordinate conversion, meta file, bitmap, icon, painting, brush, area, straight line, curve, font, color
Color, path, cut, printing, etc.
? system service. Applications use to achieve basic multitasking Win32 API part, involving processes
And thread, memory management, network, dynamic link, security, and other content related to the system.
Multimedia service. Multimedia support in Win32 API involves audio, video, media control, and multimedia
Body file input and output and enhanced timer function, etc.
• Expand library. Additional libraries for Win32 API, involving public dialogs, simplifying dynamic data exchange
(DDE) management functions, enhanced drag and drop operations in Shell, file installation function, and data decompression
function.
It will be apparent that POSIX and WIN32API are two completely different operating system interface systems. If only
These two operating systems provide the interface and function library provided by the user, it can clearly see the following characteristics:
• POSIX-based operating system interface part is much simpler than the Win32 system service part. POSIX
The interface function is about more than 200; and the function of the Win32 system service part has about 1,000, and
And the call interface is relatively complicated.
• LINUX is very rich in a library other than the operating system interface. The author used in MS-DOS, Windows
3.1, WINDOWS 95 / NT has been developed by C / C , when I contact Linux, send
Many of the originals that need to be written in the process, and there is already available functions on Linux.
13.2 Visual Studio and GNU
Developed on Windows NT, the general development tools for users are:
Microsoft Visual Studio. The development kit is the most complete development kit of Microsoft,
It is also the most widely used development kit, which contains Visual C , Visual Basic, Visual
Development tools such as FoxPro. These tools are generally integrated and developed, using these tools, can be in one
Complete the work of editing, compiling, and debugging in the program, which is helpful to improve development efficiency.
Borland C . This tool is a C / C compiler of Borland, and Visual C .
Also an integrated environment.
? Borland Delphi. This tool is a Pascal compiler developed by Borland, Borland
In order to compete with Visual Basic, the company has a broader user base, also an integration
surroundings.
Development tools on Windows NT have a feature that they are all integrated development tools. A process
Order, whether the author can truly improve the development efficiency or how to increase the development environment?
Efficiency remains skeptical. Because many programmers do not use the integrated development environment, it is also equivalent to efficient. Linux
The kernel development team is an example in which integrated development tools cannot be used when developing an operating system. use
An integrated development environment has a shortcomings that it is easy to let programmers develop lazy habits. The author is even more willing to come out
When the problem is carefully analyzed, not the debugging tool.
Unlike the integrated development environment on Windows NT, the development tools on Linux are some scattered GNU works.
. For example, a programmer may use a Vim write program, then compile the program with a Make or GCC, if the program has
Error, use GDB debugging procedures, etc. Of course, there are also some integrated development environments that can be used, such as XWPE (WindowProgramming Environment) is an integrated development environment. If you use Emacs, the programmer can also borrow
Helping Emacs's powerful configuration capabilities customize an integrated development environment.
There is still a feature of program development under Linux, that is, complicated programs can be constructed with many scripted languages. example
For example, programmers can use the shell script script, or using Perl
(Practical Extraction Report Language) Writes scripting for processing text files and generating reports
In order, you can write a graphical user interface using the TCL / TK script program. If you use these scripting languages properly,
It can achieve the effect of halving. Under Windows NT, it is probably called scripting language to be VBA (Visual)
Basic for application, but VBA is only supported in limited applications, for example, Microsoft Office,
Not being supported by operating system. Now, Microsoft is intending to add Perl's support to its operating system.
This chapter will briefly introduce some common development tools under Linux and knowledge about Perl script programming. by
The TCL / TK is mainly used to write a graphical user interface, we will explain the TCL / TK in the next chapter.
13.3 Development Tools on Linux
13.3.1 Get help
On Linux, the most common tool for programmers get help is MAN or XMAN. Util MAN or XMAN,
Programmers can view descriptions of specific functions. For example, type Man PrintF will display detailed tunes of the PrintF function
Use an interface. Since most of the software development tools on Linux come from the GNU project of the Free Software Foundation,
Programmers can use another program to get detailed help information for development tools, this program is
INFO, it is a GNU hypertext help system. Programmers can type INFO to enter the INFO help system at the command line.
Esc-x, info (or C-H, i) can also be used in EMACS to enter the INFO Help System.
In INFO, online help text is organized into a node (Node), each node represents a specific
theme. The first line on the screen shows the title of the node, as shown in Figure 13-1.
(Screen map)
Figure 13-1 Accessing the INFO Help System in Emacs
The initial screen of the INFO Help System displays a topic, you can move the cursor to the topic with *
On the menu, then press Enter to enter the topic, or type M, and then enter the topic with the name of the topic menu.
For example, you can type M, and then type GCC and enter the GCC topic.
If you want to jump between the subject, you must remember the following command keys:
? N: Jump to the next node of the node;
? P: Jump to the previous node of the node;
? M: Specify a menu name to choose another node;
? F: Enter the crossed topic;
? L: Enter the last node in this window;
? Tab: Jump to the next hypertext link of the window;
• RET: The hypertext link to the cursor;
? U: Go to the topic of the previous level; d: Back to the initial node directory of INFO;
? H: Tune the INFO tutorial;
? Q: Exited INFO.
13.3.2 GNU C and C Compiler
The most important software development tool in Linux is GCC. GCC is a GNU's C and C compiler. In fact,
GCC can compile three languages: C, C and Object C (an object-oriented expansion of C language). Use GCC life
Order can be compiled and connected to the C and C source programs.
13.3.2.1 GCC basically use
It is simple to use GCC to compile and connect a few C source files. Suppose only one of the reader's program has only one source
Document Hello.c, its contents are as follows:
#include
#include
int main ()
{
Printf ("Hello, World! / N");
Return 0;
}
Simply use the gcc -o hello hello.c to type, connect and generate an executable.
Hello:
[Weiym @ Versa GCC] $ gcc -o hello hello.c
[Weiym @ Versa GCC] $ ./hello
Hello, World!
If you have two or a few C source files, you can easily use GCC compile, connect and generate
Direct file. For example, suppose you have two source files main.c and factorial.c two source files, now you need to compile
Generate a program that calculates the multiplication. The contents of these two source files are shown in Listing 13-1 and Listing 13-2.
Listing 13-1 Factorial.c
---------------------------------------
#include
#include
INT FACTORIAL (INT N)
{
IF (n <= 1)
Return 1;
Else
RETURN FACTORALEAL (N - 1) * n;
}
---------------------------------------
Listing 13-2 Main.c
---------------------------------------
#include
#include
INT FACTORIAL (INT N);
INT main (int Argc, char ** argv)
{
Int n;
IF (argc <2) {
Printf ("USAGE:% S N / N", Argv [0]);
Return -1;
}
Else {
n = atoi (Argv [1]);
Printf ("Factorial Of% D IS% D. / N", N, Factorial (N));
}
Return 0;
}
---------------------------------------
Use the following command to compile the generated executable and execute the program:
[Weiym @ Versa GCC] $ gcc -o factorial main.c factory.c
[Weiym @ Versa GCC] $ ./factorial 5
Factorial of 5 IS 120.
In the above GCC command option, a -O option is used, which specifies the output of compilation / connection generation.
The name of the file. If you do not specify the name of the output file, the GCC automatically creates an A.out file.
We can also compile these two files, and then connect, then use GCC-C selection.
Item, as shown below:
[Weiym @ Versa GCC] $ gcc -c main.c
[Weiym @ Versa GCC] $ gcc -c factory in
[Weiym @ Versa GCC] $ GCC -O Factorial Main.o Factorial.o
[Weiym @ Versa GCC] $ ./factorial 10
Factorial of 10 IS 3628800.
13.3.2.2 Compile C programs with GCC
GCC can be used simultaneously to compile C processes and C programs. In general, the C compiler passes the reproduction of the source file.
To determine whether the C program is still a C program. In Linux, the suffix of the C source file is called .c, and C source
The suffix of the part is .c or .cpp.
However, the GCC command can only compile C source files, and the library that cannot be automatically used automatically and C programs. therefore,
The G commands are usually used to complete the compilation and connection of the C program, which automatically calls GCC implementation compilation.
Suppose we have a C source file (Hello.c):
#include
Void main (void)
{
Cout << "Hello, World!" << Endl;
}
You can call G commands as follows, Connect, and generate executables:
[Weiym @ Versa GCC] $ G -o Hello Hello.c
[Weiym @ Versa GCC] $ ./hello
Hello, World!
13.3.2.3 Other options for GCC
The basic syntax of the GCC command is:
GCC Options FileName
The option of GCC is generally started with a minus (-), there is a short option, such as -O or -c as seen above, has a long
Options. Table 13-1 gives a common option for GCC commands.
Table 13-1 Common options for GCC Commands
Option
Explanation
-ansi
Only the ANSI standard C syntax is supported. This option will prohibit certain features of GNU C,
For example, ASM or TypeOf keywords.
-C
Only compile and generate the target file.
-Dmacro
Define the MacRo macro with "1" in strings.
-Dmacro = DEFN
Define the Macro macro with a string "DEFN".
-E
Run only the C pre-compiler.
-g
Generate debugging information. The GNU debugger can take advantage of this information.
-IDIRECTORY
Specifies the extra first file search path Directory.
-Ldirectory
Specify an additional library search path Directory.
-llibrary
Search the specified function library library when connecting.
-M486
Code optimization for 486.
-o file
Generate the specified output file. When generating an executable file.
-O0
Not optimized.
-O or -o1
Optimize the generated code.
-O2
further optimization.
-O3
Further optimize than -O2, including the inline function.
-shared
Generate a shared target file. Usually used when building a shared library.
-static
It is forbidden to use a shared connection.
-Umacro
Cancel the definition of the Macro macro.
-w
No warning information is generated. -Wall
Generate all warning information.
Other examples of GCC can be found on the INFO Help or GCC man page. As an example, please see the following GCC life
make:
$ Gcc -o test -d_debug -g -i ../ incdude / -l ../ lib -lmylib test.c
The above command compiles and generates the executable TEST. The -d option defines a _debug macro, -g specified life
The debug information, -i and -L specify an extra header file and an additional function library path, -L
Specify a search function library when a connection is set.
13.3.3 GNU Make Tools
In large development projects, there are usually dozens to hundreds of source files. If you are manually typed, you can type GCC life.
If you have compiled, it will be very inconvenient. Therefore, people usually use the MAKE tool to automatically complete the compilation.
These tasks include: If you only modify a few source files, only these source files are recompiled; if a one is
The pieces are modified, then all source files that contain the header file are recompiled. Utilize this automatic compilation, greatly simplified development
Work, avoid unnecessary recompilation.
In fact, the Make tool completes and automatically maintains compilation through a file called Makefile.
Makefile needs to be written in a syntax, which describes how to compile individual source files and connect to generation.
Direct file and define dependencies between source files. If you modify one of the source files, if other source files
Depending on this file, you should also recompile all source files that depend on the file. Makefile file is a lot of compilers,
Including compiler under Windows NT Maintains Common Method for Compile Information, just in integrated development environments, users
The friendly interface modifies the Makefile file.
By default, GNU Make Tools Search Makefile in the order in the current working directory:
? Gnumakefile
? Makefile
? Makefile
In UNIX systems, use Makefile as a Makfile file. If you want to use another file
To make Makefile, you can specify the makefile file with the following MAKE command options:
$ Make -f Makefile.debug
13.3.3.1 Makefile content
Makefile usually contains the following:
• Items that need to be created by the Make tool, usually the target file and executable. Usually use "
"Target" is the term to represent the project to be created.
? Projects to be created depend on which files are dependent.
• The command that needs to be run when you create each item.
For example, suppose you now have a C source file Test.c, the source file contains a custom header file
Test.h, the target file Test.o explicitly depends on two source files: Test.c and Test.h. In addition, you may
Just want to use the G command to generate a Test.o target file. At this time, you can use the following makefile.
Define Test.o creation rules:
# This makefile Just is a example.
# The folowing lines indicate how test.o dependeed
# Test.c and test.h, and how to create test.o
Test.o: test.c test.h
G -c -g test.c
From the above example notes, the first character is a # 行 注 行 行 行. The first non-promised line specifies Test.o as a target and rely on Test.c and Test.h files. Subsequent lines specify how to build files depending on the target
Target.
When Test.c or Test.h file is modified after compiling, the make tool can automatically recompile
Test.o, if there is two compilations between the front and rear, Test.c and Test.h have not been modified, and Test.o is still
If you exist, it is not necessary to recompile. This dependency is especially important in program compilation of multi-source files. by
This definition of this dependency, the Make tool avoids many unnecessary compilation work. Of course, use shell scripts
You can also achieve the effect of automatic compilation, however, the shell script will all compile any source files, including which unnecessary
Reheactive source files, while the Make tool can be based on the source files depending on the time and the target of the target.
Update time and automatically determine which source file should be compiled.
A Makefile file can define multiple targets, using the make target command to specify the purpose to be compiled
Sign, if you do not specify a target, use the first target. Typically, as a Clean target is defined in Makefile, available
To clear the intermediate files during the compilation process, for example:
Clean:
RM -F * .O
When running make clean, the RM -F * .O command will be executed, and finally delete all of all the compilation processes.
Document.
13.3.3.2 Variables in Makefile (Macro)
In addition to the basic functions of establishing goals, GNU's Make tools, there are many convenient relationships.
And the characteristics of the command to establish the target. One of them is the definition of variables or macros. If you have to compile the same
Options simultaneously compile for more than a dozen C source files, and the test of each target specifies the lengthy compile option, it will be
Everbrust. But using simple variables definition to avoid this boring job:
# Define Macros for Name of Compiler
CC = GCC
# Define a macr o for the cc flags
Ccflags = -d_debug -g -m486
# A rule for building a object file
Test.o: test.c test.h
$ (Cc) -c $ (ccflags) Test.c
In the above example, CC and CCFLAGS are MAKE variables. GNU Make is usually called variables,
And other UNIX Make tools are called macro, it is actually the same thing. Reference variables in makefile
To add $ symbols before the variable name, the $ (cc) and $ (ccflags) above are added.
GNU Make has many predefined variables that have special meanings and can be used in rules. Table 13-2
Some major predefined variables are given, in addition to these variables, GNU Make also uses all environment variables as oneself
Predefined variables.
Table 13-2 Main predefined variables of GNU Make
Predefined variable
meaning
$ *
The name of the target file that does not contain the extension.
$
All dependencies are separated by spaces, and may contain duplicate dependencies in order to appear.
$
The first name that relies on the file.
$?
All dependencies are separated by spaces, and these dependencies have been dated than the date of creation of the target.
$ @ @ @ @ @ @
The full name of the target.
$ ^
All dependencies, separated by space, does not contain duplicate dependencies. $%
If the target is an archive member, the variable indicates the name of the target of the target. For example, if the target name is
MyTarget.so (Image.), $ @ is myTarget.so, and $% is image.o .o.
Ar
The name of the archive maintenance program, the default value is Ar.
Arflags
Archive Maintenance Options.
AS
The name of the assembler, the default is as.
Asflags
The options for assemblers.
CC
The name of the C compiler, the default value is CC.
Cflags
The option for the C compiler.
CPP
The name of the C precompiler, the default value is $ (cc) -e.
CPPFlags
C precompiled option.
CXX
The name of the C compiler, the default value is G .
CXXFlags
C compiler options.
FC
The name of the Fortran compiler, the default value is F77.
Fflags
Options for the Fortran compiler.
13.3.3.3 Include rules
GNU Make contains a number of built-in or implicit rules that define how from different dependencies
Establish specific types of goals. GNU Make supports two types of implicit rules:
? Suffix rules. Suffix rules are old-style methods that define hidden rules. Suffix rule
Define a file that has a suffix (for example, .c file) to have another suffix
Method of files (eg, .o files). Each suffix rule is defined in two pairs of suffixes.
For example, the suffix rule converts the .C file to the .o file can be defined as:
.c.o:
$ (Cc) $ (cflags) $ (cppflags) -c-@ @ $ <
Pattern Rules. This rule is more common because it can be defined using the mode rule
More complex dependency rules. Mode rules look very similar to regular rules, but in the target name
The front is more than one%, and it can be used to define the relationship between the target and dependencies, such as below.
The pattern rule defines how to convert any of the X.c file to the X.O file:
% .c:%. O
$ (Cc) $ (cflags) $ (cppflags) -c-@ @ $ <
13.3.3.4 Makefile instance
An instance of a Makefile is given below, see Listing 13-3.
Listing 13-3 Example of a MAKFILE file
---------------------------------------
# ------------------------------------------------- ---------------------
# Makefile for test programs of minigui4 for linux.
# CopyRight (C) 1999, wei yongming.
#
# ------------------------------------------------- ---------------------
# THESE MAY BE CHANGED, IF DESIRED
CC = GCC
CCOPTS = -O2 -wall -m486 -d_reentrant
# ------------------------------------------------- ------------------ #
CFLAGS = $ (ccopts)
TestProg = TestGuitestobj = testgui.o misc.o gdi.o cursor.o Event.o Desktop.o /
Window.o main.o cliprect.o menu.o fixstr.o timer.o dti.o
All: $ (TestProg)
$ (TESTPROG): $ (Testobj)
$ (CC) -O $ (TestProg) $ (Testobj) -lvgagl -lvga -lpthread
Clean:
RM -F * .O * ~. *. SWP. *. SWO
TestGui.o: window.h Event.h misc.h gdi.h Cursor.h main.h common.h
CLIPRECT.O: CLIPRECT.H Common.h
Misc.o: misc.h gdi.h cliprect.h common.h
gdi.o: gdi.h cliprect.h misc.h Common.h
Cursor.o: cursor.h gdi.h cliprect.h misc.h Common.h
Event.o: Event.h Cursor.h Misc.h Common.h
Desktop.o: menu.h fixstr.h cliprect.h window.h event.h cursor.h /
GDI.H Misc.h Common.h
WINDOW.O: Menu.h fixstr.h cliprect.h window.h event.h cursor.h /
GDI.H Misc.h Common.h
Menu.o: menu.h fixstr.h cliprect.h window.h Event.h Cursor.h /
GDI.H Misc.h Common.h
Fixstr.o: fixstr.h common.h
Timer.o: Timer.h WINDOW.H GDI.H ClipRect.h inline.h Common.h
DTI.O: menu.h window.h gdi.h cliprect.h inline.h common.h
Main.o: main.h common.h
---------------------------------------
In the above Makefile file, multiple goals and dependencies of other source files are defined. We can
To notice that some variables are defined in the above Makefile, compiling each other using the Holnu Make's built-in implicit rules
A .c source file. The output when executing the make command is as follows:
[Weiym @ Rocket SRC] $ make clean
RM -F * .O * ~. *. SWP. *. SWO
[Weiym @ Rocket SRC] $ MAKE
GCC -O2 -Wall-M486 -D_reentrant -c testgui.c -o testgui.o
GCC -O2 -WALL -M486 -D_REENTRANT-C Misc.c -o misc.o
GCC -O2 -WALL -M486 -D_REENTRANT -C GDI.C -O GDI.O
GCC -O2 -WALL -M486 -D_REENTRANT -C CURSOR.C -O CURSOR.O
GCC -O2 -WALL -M486 -D_REENTRANT-C Event.c -o Event.o
GCC -O2-Wall-M486 -D_reentrant -c desktop.c -o desktop.o
GCC -O2 -WALL -M486 -D_REENTRANT-C window.c -o window.ogcc -O2 -wall -m486 -d_reeTrant -c main.c -o main.o
GCC -O2 -wall -m486 -d_reentrant -c clipRect.c -o clipRect.o
GCC -O2 -WALL -M486 -D_REENTRANT -C MENU.C -O Menu.o
GCC -O2 -WALL -M486 -D_REENTRANT -C FixStr.c -o fixstr.o
GCC -O2 -WALL -M486 -D_REENTRANT -C Timer.c -o Timer.o
GCC -O2 -WALL -M486 -D_REENTRANT-C DTI.C -O DTI.O
GCC -O TestGui Testgui.o misc.o gdi.o cursor.o Event.o desktop.o window.o main.d
13.3.3.5 Common options for MAKE commands
We know that the target name can be established directly to establish a designated target directly after the Make command.
Establish the first goal. We also know that Make can specify make -f mymakefile
Use specific makefile instead of the default gnumakefile, makefile or makefile. GNU Make
There are still some other options, and these options are given in Table 13-3.
Table 13-3 General command line options for GNU Make Commands
Command line option
meaning
-C DIR
Change to the specified directory DIR before reading Makefile.
-f file
As the specified File file as Makefile.
-H
Display all Make options.
-i
Ignore all commands to perform errors.
-I DIR
When containing other Makefile files, you can specify the search directory using this option.
NN
Print only the command to be executed, but do not perform these commands.
-p
Display the MAKE variable database and implicit rules.
-S
Do not display the command when the command is executed.
-w
The working directory is displayed before and after processing makefile.
-W file
Assume that the file file has been modified.
13.3.4 GNU debugger
The GNU debugger is called GDB, which is an interactive tool that works in character mode. Department of X Window
In the system, there is a front-end graphic tool for GDB, called XXGDB. GDB is a powerful debugger that is completed
The following debug task:
• Set breakpoints;
• Monitor the value of the program variable;
• Single step execution of the program;
? Modify the value of the variable.
You must compile the source file with the -g option before you can use the GDB debugger. Can be in Makefile
Define the CFLAGS variable as follows:
Cflags = -g
13.3.4.1 Run GDB
Usually use the following command when running a GDB debugger:
GDB Progname
After performing the above command, the GDB will display a command prompt:
[Weiym @ Rocket SRC] $ GDB TESTGUI
GNU GDB 4.17.0.4 with Linux / x86 Hardware WatchPoint and FPU Support
CopyRight 1998 Free Software Foundation, Inc.
GDB IS Free Software, Covered by the gnu general public license, and you are
Welcome to change it and / or dispibute copies.type "show copying" to see the conditions.
There Is Absolutely No Warranty for GDB. Type "Show Warranty" for Details.
THIS GDB WAS Configured AS "i386-redhat-linux" ...
(No Debugging Symbols Found) ...
(GDB)
(GDB) is the prompt of GDB. Type HELP at the GDB prompt, the classification of the command will be listed, the main points
Category:
? Aliases: command alias
? Breakpoints: breakpoint definition;
Data: Data View;
Files: Specify and view files;
• Internals: maintenance command;
• Running: Program execution;
? Stack: Call Stack View;
• Statu: Status View;
• TRACEPOINTS: Tracking program execution.
Type the classification name of the command after Help, you can get a detailed list of this class command. For example, type Help Stack,
Will get the following command list:
(GDB) Help Stack
Examining the stack.
The Stack is Made Up of Stack Frames. GDB Assigns Numbers to Stack Frames
Counting from Zero for the Innermost (Currently Executing) Frame.
(LINES Deleted)
List of commands:
Backtrace - Print Backtrace of All Stack Frames
BT - Print Backtrace of All Stack Frames
Down - Select and Print Stack Frame Called by this One ONE
Frame - SELECT and Print A Stack Frame
Return - Make Selected Stack Frame Return To ITS Caller
SELECT-FRAME - SELECT A Stack Frame without Printing Anything
Up - Select and Print Stack Frame That Called this One ONE
To exit GDB, simply type Q at the prompt and press ENTER.
Table 13-4 lists commonly used GDB commands.
Table 13-4 Common GDB Commands
command
Explanation
Break Num
Set breakpoints on the specified row.
BT
Display all call stack frames. This command can be used to display the call sequence of the function.
Clear
Delete Settings in a specific source file, breakpoint on a particular line. The usage is: Clear FileName: Num.
Continue
Continue to execute procedures being debugging. This command is used to stop running due to processing signals or breakpoints.
Display expr
The value of the expression is displayed after each program is stopped. The expression consists of a variable defined by the program.
FILE FILE
Load the specified executable to debug.
Help name
Displays help information for the specified command.
Info Break
Displays the current breakpoint list, including the number of times at breakpoints, and the like.
Info files
Details showing the debugged file. INFO FUNC
Display all function names.
Info local
Display local variable information in the function.
INFO PROG
Displays the execution status of the debugged program.
Info var
Display all global and static variable names.
Kill
Terminate the procedure being debugged.
List
Displays the source code segment.
Make
Run the Make tool without exiting GDB.
NEXT
Perform a row source code forward without single step in entering other functions.
Print EXPR
Displays the value of Expression EXPR.
quit
Exit GDB.
Set variable
Set the value of the variable, the syntax is set variable var = value.
Shell cmd
Execute the shell command without exiting GDB.
STEP
Perform a row source code forward, if possible, jump into the call function.
Watch var
When the value of the variable VAR changes, the value of the variable is displayed.
WHERE
Display the call sequence. Depending on the output of this command, you can find a problem with the program.
X / f addr
Check the memory address for the content of addr, f Specify the displayed format. Take advantage of
x: Hexadecimal O: Octa D: Decang
u: No symbol decimal T: binary f: floating point number, etc.
Addr generally extracts the variable name or pointer name.
13.3.4.2 Using GDB
To illustrate the use of GDB, we write a problem with a problem, see Listing 13-4.
Listing 13-4 A wrong C source program Test.c
---------------------------------------
#include
#include
Static char buff [256];
Static char * string;
int main ()
{
Printf ("" please input a string: ");
Gets (string);
Printf ("/ NYOUR STRING IS:% S / N", STRING);
}
---------------------------------------
The above program is very simple, the purpose is to accept the user's input, then print the user's input. Should
The program uses a string address String that has not been initialized, so after compiling and running, it will appear
Segment fault error:
[Weiym @ Versa GCC] $ GCC -O Test -g Test.c
[Weiym @ Versa GCC] $ ./test
Please Input A String: Asfd
Segmentation Fault (Core Dumped)
In order to find problems in the program, we use GDB and proceed as follows:
1. Run the GDB Test command to load the TEST executable;
2. Perform the loaded test command:
(GDB) RUN
Starting Program: / Home / Weiym / Projects / Study / GCC / TEST
Please Input A String: Abcd
Program received Signal SigSegv, Segmentation Fault.
0x4006a7da in _io_gets (buf = 0x0) at ogets.c: 55
IOGETS.C: 55: No Such File or Directory.
3. Use the where command to view the places where the program is wrong:
(GDB) WHERE
# 0 0x4006a7da in _io_gets (buf = 0x0) AT IOGETS.C: 55
# 1 0x8048413 in main () at Test.c: 11
# 2 0x40030cb3 in __libc_start_main (main = 0x80483f8
Argv = 0xBffFFFCA4, INIT = 0x80482bc <_init>, fini = 0x804845c <_fini>,
RTLD_FINI = 0x4000A350 <_dl_fini>, stack_end = 0xBfffffc9c)
at ../sysdeps/generic/libc-start.c:78
The output of the where command displays the call sequence of the function, the last function call, ie # 0 call is a C library
Function Gets. This function is called from the 11th row of Test.c (Main function).
4. Use the list command to view the code near the CENS function:
(GDB) List test.c: 11
6
7 int main ()
8 {
9
10 Printf ("Please Input A String:");
11 gets (string);
12
13 Printf ("/ NYOUR STRING IS:% S / N", String);
14}
15
5. The only factor that can cause a gets function error is the variable string. View String with the print command
Value:
(GDB) Print String
$ 1 = 0x0
Obviously, a null pointer is passed for the Gets function, which is the error of the program. This is because String is
A global variable, which is initialized to 0, an empty pointer.
6. In GDB, we can directly modify the value of the variable, just take the String a legal pointer value.
Yes, for this, we set breakpoints at the 11th line:
(GDB) BREAK 11
Breakpoint 1 at 0x8048408: File Test.c, Line 11.
(GDB) RUN
The Program Being Debugged Has Been Started ALREADY.
START IT from the basenning? (Y or n) y
Starting Program: / Home / Weiym / Projects / Study / GCC / TEST
Breakpoint 1, Main () at Test.c: 11
11 gets (string);
7. The program stopped until the 11th line, then we can use the set variable command to modify the String
Take the value:
(GDB) set var string = buff
8. Then continue to run, will see the correct program run:
(GDB) CONT
Continuing.
Please Input A String: Abcd
Your string is: abcd
Program evted with code 026.
The above example is sufficient to illustrate the general use of GDB, of course, the commands of GDB have a lot of commands, and can also be used to debug multi-threaded programs. The use of these commands requires readers to learn and master them in practice.
13.3.5 Version Control Tools
During the development of small software, use the Make tool to automatically complete some compilers. If it is involved
There are not many developers, and the maintenance of the code is simple. People usually use backup and mandatory code annotations to maintain the source
Order modification. However, in large projects, the developer and code are very large, it is necessary to use specialized
Version control software to maintain the revision of the code. In Microsoft's development tool, there is a SourceSafe
Software, specifically used to control, in large-scale development tools such as PowerBuilder, there is usually built-in
Version control system. On Linux, the usual version control system is called RCS, which Revision Control
System.
Using version control systems, developers can restore specific versions or revisions of a file when needed. In use
When the version control system, the developer's modification of a file is processed as follows:
1. When the developer has an initial source file version, archive the file into the version control system.
2. When the developer needs to modify a file, first get a copy of the current version. In a certain
When a developer gets a copy of the file, the version control system will ensure that other people cannot get the file.
3. When the dialog is modified, the developer saves the file as a new version.
4. This will then modify the file, will always be modified on the latest version of the file.
To this end, RCS provides many tools to help maintain the revision of source code, and the main tools are shown in Table 13-5.
Table 13-5 RCS main tools
Tool name
Features
Ci
Establish a new revision of a file or add a work file to the RCS file.
CO
Get a job version of a file for read-only purposes. (Co -l provides a working file and locking the original
This file can be modified. )
Ident
Search identifiers in the file.
Merge
Bring two files into the third file.
RCSDIFF
Compare the work files and RCS maintenance.
RCSMERGE
Merge of different versions of a file.
rlog
View the modification log of a file.
Limited to the space cannot explain the use of RCS in detail, please refer to the RCSINTRO (1) man page and the phase
Take help information.
13.3.6 Introduction to Perl
Linux provides developers with a vast event stage. Developers can not only use C / C , Fortran,
Pacal, Lisp and other programming language written programs, and can write programs in various scripting languages, including
Shell script, Perl script, TCL / TK script, etc. Usually, the scripting language is a programming language, but it
Close to natural language, with simple, convenient features, and in some ways, compared to traditional programming languages
More advantageous.
This section will briefly describe the scripting language Perl used in Linux. Perl, Practical
Extraction Report Language (Practical Reporting Report Language), created by Larry Wall, can be used from text
Decompose information in this document and use this information to establish a report. Due to Perl and Linux, it is also free soft.
Part, therefore, Perl is widely circulated in various computer systems. Various Linux business issued versions include Perl.
13.3.6.1 Execution of Perl scripts
Unlike traditional compilation languages, Perl scripts are generally some text files, interpreted by the Perl program and executed
Perl script. For example, the following is a simple Perl script:
#! / usr / bin / perl
# This is a comment.
Print "Hello, World! / N"
The first line of this script uses #! Specifies the explanation of the script as / usr / bin / perl, the second line is a note
Release, the third line print "Hello, World!".
Before performing this script, first set the script file to an executable mode. If the script name is Hello.pl
(.Pl is typically the suffix name of the Perl script), use the following command:
$ Chmod x hellol.pl
Then you can perform Hello.pl directly on the command line:
$ ./Hello.pl
In fact, Linux will execute the script as follows:
/ usr / bin / perl ./HELLO.PL
13.3.6.2 Basic syntax of Perl
Perl contains the same common features as other languages:
• Variables used to save different types of data.
• Expression of a combination of variables using an operator.
• Perform actions of action.
• Control the statement to execute the stream control statement of the route.
• Division function, provide functions of reusability (subroutines, or routines).
The writing form of the Perl program is free, and C is similar, each perl statement ends with a semicolon (;), # generation
Table A Note, Perl also defines a statement group with Co-Calbum ({...}).
The following section describes Perl variables, operators, and expressions, statements, stream controls, and other features.
13.3.6.3 variable
In the Perl program, you don't have to display the definition variables, all variables are headed by @, $ or%, representing Perl, respectively.
Three variable types.
• Scarr variable (SCALAR VARIABLE). Scalar type variable defines basic data types, including
Number, floating point and string. The scalar type variable begins with a character:
$ title = "Linux and windows nt";
$ count = 10;
• Array Variable. An array variable is a collection of scalar variables, array type variables
The prefix is @, as shown below:
@commands = ("LS", "DIR", "CD", "RM", "MV");
@LENGTH = (2, 3, 2, 2, 2);
Elements in arrays can be accessed by a subscript method similar to a C language, for example:
$ comMMANDS [0]
• Associate array. Associated arrays are some collection of key / value, the keys
It is a string, and the value can be any scalar type variable. The prefix of the associated array is%. Use off
The association array can quickly find the corresponding value via a string key, as shown below:
% grades = ("WeiYM", 60, "zhengx", 100, "other", 50);
Use {key} to request the keys in the associated array: $ mygrade = $ grads {weiym}
It should be noted that in the statement, when the variable is in the dual quotation mark (""), Perl will evaluate the variable,
When the variable is in single quotation (''), Perl does not evaluate the variable. The following two statements will be different
content:
Print "My grade is $ grads [weiym] / n"; # output: my grade is 60
Print 'my grade is $ grads [weiym] / n'; # output: my grade is $ grads [weiym] / n
Perl has some predefined variables, including:
? @Argv: String array, contains a string option for scripts. ARGV ginseng similar to the C language main function
number.
?% EVN: Associated an associated array containing environment variables. For example, $ evN {home} is the user's home directory.
? $$: Process ID of the script.
$ <: The user ID of the script is run.
? $ ?: Near the return status of a system call.
$ _: The default parameters of many functions.
$ 0: Script Name.
13.3.6.4 Operators and Expressions
The operator is used to combine and compare the Perl variables, and Perl provides almost a operator like C. Including
, -, *, / and other arithmetic operators, and>, <,> =, <=, ==, etc., [] actual
Is the index operator of Perl.
However, the operator defined by the C language is very basic, we cannot compare strings with operators such as ==. In Perl
Also, in order to compare the string, Perl defines the two strings to compare two strings similar to the Fortran operator EQ.
Whether equal:
IF ($ INPUT EQ "quit") {
EXIT;
}
Other comparisons similar to Fortran are: ne (not equal), LT (less), GT (greater than), Le (less than or
Aliquot, GE (greater than or equal). You can also use the CMP operator to compare the string, will return -1, 0, 1 equivalent,
The return value is similar to the return value of the C function STRCMP.
Other unique operators provided by Perl are:
? **: Index operator, such as:
$ y ** = 2;
(): Empty number operator, can be used to initialize array variables, such as:
@Commands = ();
?: String Connection Operator, can be used to connect two string variables, such as:
$ Message = $ part1. $ part2;
• X =: Dress operator, can use the operator to repeat the number of times specified by the string, such as:
$ marker = "*";
$ marker x = 80; # $ maker will contain 65 *
? ..: Range Operators, can be used to easily initialize strings using this operator, such as:
$ alphabet = ('a' .. 'z'); in Chapter VII, we understand the regular expression. In Perl, regular expressions have been widely used.
E.g:
IF ($ name = ~ / [ww] ei [yy] [mm] /) {
Print "$ name is a bad man./N";
}
The print statement will be performed when "weiym" or "weiym" will be taken in $ NAME. Note that in the above statement, regular expression
Enclosed by / /, check if it matches, uses = ~ operators (check when not matching, using! ~ Operator).
13.3.6.5 Flow control statement
Perl provides the same stream control statement as the C language and contains some extra features. Perl conditions
The form of statements is as follows:
Conditional-statement {
Perl Code to Execute if Conditional IS TRUE
}
Note that the braces that enclose the execution code must exist, this point and C language is different. It is worth pointing out that Perl
Like C, regard any non-zero value as true, and see zero as False.
Table 13-6 briefly gives the flow control statement of Perl.
Table 13-6 Flow control statement of Perl and its use
Stream control statement
Description
Example
IF
Similar to the IF statement of the C language. Elseif
And ELSE clauses.
IF ($ USER EQ "root") {
Print "The Super User./N";
} else {
Print "a Normal User./N";
}
Unless
The same use as the IF statement, including Elseif and
ELSE clause. Its judgment results are the opposite of IF.
Unless ($ USER EQ "root") {
Print "a Normal User./N";
}
While
Similar to the WHILE statement in the C language. And C language
The Break and Continue statements correspond to the respective respective
Last and NEXT statements.
While (
Print $ _;
}
for
Similar to the C language for statement syntax.
For ($ I = 0, $ SUM = 0; $ I <= 10; $ i ) {
$ SUM = $ i;
}
Foreach
Can be used to handle a special for statement of an array.
Foreach $ I (1..10) (
$ SUM = $ I;
}
goto
The use of the GOTO statement is the same as the C language.
REDO:
IF (
Print $ _;
Goto Redo;
}
13.3.6.6 Access System
Perl can execute the Linux command by the following channels:
? Call the system to pass the Linux command to be executed.
• Specify the Linux command in a pair of demo (`).
Call the Fork function, similar to the Linux's Fork system call. Will copy the current script and in sub-process
Process new commands.
• Call the Exec function, similar to the EXEC system call for Linux. Will now overwrite the current script or command
script.
• Use Fork and Exec to provide a function similar to the shell (via the child process to monitor the user's input and
Handle the user command).
We will give an example in order to explain the last command execution pathway, see Listing 13-5.
Listing 13-5 psh.pl - use fork and exec to perform user commands ------------------------------- --------
#! / usr / bin / perl
# This script uses "fork" and "EXEC"
# To perform commands typed by users
$ prompt = "Command (/" exit / "to quit):";
Print $ PROMPT;
While (
Chop; # 清除 / / /
IF ($ _ EQ "EXIT") {exit 0;}
$ status = for;
IF ($ status) {
# This is a parent process, waiting for the sub-process to end
Wait;
Print $ PROMPT;
NEXT;
} Else {
Exec $ _;
}
}
---------------------------------------
Execute the above script will result in the following results:
[Weiym @ versa perl] $ ./psh.pl
Command ("exit" to quit): PS
PID TTY TIME CMD
670 PTS / 1 00:00:00 Bash
807 PTS / 1 00:00:00 psh.pl
808 PTS / 1 00:00:00 PS
Command ("exit" to quit): EXIT
13.3.6.7 file processing
As you can see from the previous example, Perl uses stdin as the identifier of the standard input. In Perl,
The file is represented by the handle, usually used in uppercase. In addition to stdin, there are two predefined files in Perl.
The handle, that is, Stdout and STDERR, represent the standard output device and the error output device, respectively.
If you want to use another file, you can use the Open function to open the file, close the file with the Close function,
And use
Open (pwdfile, "/ etc / passwd);
While (
Close Pwdfile;
13.3.6.8 User Custom Rollers
Perl contains a lot of built-in functions, but users can customize routines. Use in Perl scripts
The routine is very simple:
#! / usr / bin / perl
Sub Display
{
# Copy the function parameters to local variables
Local ($ Name, $ x) = @_;
Print "Grade of $ Name IS $ x / n";
}
% grades = ("WeiYM", 60, "zhengx", 100, "other", 50);
& Display ("WeiYM", $ grades {weiym});
& Display ("ZHENGX", $ grades {zhengx});
& Display ("Other", $ grades {oo};
The results of the above scripts are as follows:
[Weiym @ Versa Perl] $ ./grad.pl
Grade of weiym is 61
Grade of zhengx IS 100
Grade of Other IS 50
Perl provides users with more than 160 built-in functions, some of which are functions in the C standard library function, and others are functions for accessing the operating system. See the Perlfunc manual for details on the built-in function.
page. Other information about Perl is also divided into separate manuals, and summary information can be referred to in the Perl man page.
13.4 related programming style
The purpose of writing this section is to remind the reader to pay attention to the programming style during the programming process. If you are just writing some
The small exercise program, the program is only one or two hundred years of long, the programming style may not be important. However, if you and a lot
People develop work together, or, you want to understand your own procedures after a while,
It is necessary to develop good programming habits. In many programming habits, the programming style is the most important thing.
Good programming style can help developers in many ways. If you read Linux kernel source code
If you may pour a beautiful proof of the program. A good programming style can increase the readability of the code and help you
Ruand the head. If the program is very messy, it will give you a halo. The programming style is best to reflect one
Programmer's overall quality.
However, if you compare the programs under both Windows and Linux, it will be found in the programming style.
Two systems have a relatively large difference.
Many readers may be familiar with Hungarian nomenclature respected by Windows. This method is defined very complex
Named methods of functions, variables, types, etc.
Name, use the added prefix to represent its type, for example:
Char szbuffer [20];
Int ncount;
Use SZ and N to represent strings and integers, respectively. In order to represent a variable name, the following variable name is used.
possible:
Int IthisaverylongVariable;
In Win32API, functions with complex names and calling parameters are uncommon, for example:
Bool GetSecurityDescriptorControl
Psecurity_descriptor PsecurityDescriptor,
Psecurity_Descriptor_control pcontrol,
LPDWORD LPDWREVISION;
In Linux, we often see that the definition is a very simple function interface and variable name. In Linux
In the source code of the core, you can see the encoding style of Linux kernel source code (
Documentation / CodingStyle). We have repeatedly mentioned the exquisite characteristics of UNIX systems and the building blocks.
Plan the principle. C language originated from the UNIX operating system, like UNIX design principles, C language is widely recognized
An important reason for use is its flexibility and simplicity. Therefore, when writing programs with C language, start
It should eventually meet its simple design principles without using a very complex variable naming method. Linus is Linux
Nuclear defined C language coding style points are as follows:
1. When indent, use a length of 8 characters wide. If the procedure has more than 3,
Through the redesign program.
2. Brand position. In addition to the definition of the function, the left brage should be placed in the end of the row, and the right brace is placed.
In the lead. The definition body of the function should be placed on the lead. As follows:
Int Function (int x, int y)
{
IF (x == y) {
...
} Else if (x> y) {
...
} Else {
...
}
Return 0;
}
3. A concise naming method should be used. For the variable name, do not agree with the form of case in cases, but encourage use
Descriptive name; not using global variables as much as possible; non-use of the Hungarian nomenclature to indicate the type of variable;
The fine name represents a partial variable; keep the function short, avoiding too much local variables.
4. Keep the function short.
5. The role of the annotation should not be excessively emphasized, should try to use a good coding style rather than adding too much comments.
13.5 small knot
In many ways, Linux and Windows NT are different in many ways, and this chapter is from the operating system.
The interface starts, simply compare Linux and Windows NT in system interface, function library, programming tool, and encoding
Different from style. Considering that many readers will carry out application software development on Linux, this chapter
I have explained the development tools mainly used when software development on Linux, including:
? GNU C, C compiler
? GNU Make Tool
? GNU debugger
? RCS version control system
This chapter also briefly introduces the popular Perl scripting language on Linux systems.
In fact, the concept of programming is everywhere in Linux systems, and many tools provide similar programming languages.
Variable definition, grammar, rules, etc. Therefore, the Linux system provides programmers with a broader stage.
Regardless of Linux or on Windows NT, graphical user interface programming is a very heavy in software development.
The topic you want. The next chapter will focus on the X Window software development on Linux and the application of Windows NT.
A comparison of the development of a piece.