Linux prog

Linux prog - 15 0430 APPA 10:53 AM Page 259 A Other...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Other Development Tools A D EVELOPING CORRECT , FAST C OR C++ GNU/L INUX PROGRAMS requires more than just understanding the GNU/Linux operating system and its system calls. In this appendix, we discuss development tools to find runtime errors such as illegal use of dynamically allocated memory and to determine which parts of a program are taking most of the execution time.Analyzing a program’s source code can reveal some of this information; by using these runtime tools and actually executing the program, you can find out much more. A.1 Static Program Analysis Some programming errors can be detected using static analysis tools that analyze the program’s source code. If you invoke GCC with -Wall and -pedantic , the compiler issues warnings about risky or possibly erroneous programming constructions. By eliminating such constructions, you’ll reduce the risk of program bugs, and you’ll find it easier to compile your programs on different GNU/Linux variants and even on other operating systems.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
260 Appendix A Other Development Tools Using various command options, you can cause GCC to issue warnings about many different types of questionable programming constructs.The -Wall option enables most of these checks. For example, the compiler will produce a warning about a comment that begins within another comment, about an incorrect return type specified for main , and about a non void function omitting a return statement. If you specify the -pedantic option, GCC emits warnings demanded by strict ANSI C and ISO C++ compliance. For example, use of the GNU asm extension causes a warning using this option.A few GNU extensions, such as using alternate keywords beginning with __ (two underscores), will not trigger warning messages.Although the GCC info pages deprecate use of this option, we recommend that you use it anyway and avoid most GNU language extensions because GCC extensions tend to change through time and frequently interact poorly with code optimization. Listing A.1 ( hello.c ) Hello World Program main () { printf (“Hello, world.\n”); } Consider compiling the “Hello World” program shown in Listing A.1.Though GCC compiles the program without complaint, the source code does not obey ANSI C rules. If you enable warnings by compiling with the -Wall -pedantic , GCC reveals three questionable constructs. % gcc -Wall -pedantic hello.c hello.c:2: warning: return type defaults to ‘int’ hello.c: In function ‘main’: hello.c:3: warning: implicit declaration of function ‘printf’ hello.c:4: warning: control reaches end of non-void function These warnings indicate that the following problems occurred: n The return type for main was not specified. n The function printf is implicitly declared because <stdio.h> is not included.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 22

Linux prog - 15 0430 APPA 10:53 AM Page 259 A Other...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online