Tải bản đầy đủ - 0 (trang)
#7. More on make

#7. More on make

Tải bản đầy đủ - 0trang

leftovers



Implicit rules

The make tool knows quite a lot about C compilation, and it can

use implicit rules to build files without you telling it exactly how.

For example, if you have a file called fred.c, you can compile it

without a makefile by typing:



cc will usually

be another

name for gcc.



File Edit Window Help MakeMyDay



> make fred

cc fred.c -o fred



This compile command was

created by make, without

us telling it how.



This is an implicit rule.



That’s because make comes with a bunch of built-in recipes. For

more on make, see:

http://www.gnu.org/software/make/



you are here 4   549



www.it-ebooks.info



development tools



#8. Development tools

If you’re writing C code, you probably care a lot about

performance and stability. And if you’re using the GNU Compiler

Collection to compile your code, you’ll probably want to take a look

at some of the other GNU tools that are available.



gdb

The GNU Project Debugger (gdb) lets you study your compiled

program while it’s running. This is invaluable if you’re trying to

chase down some pesky bug. gdb can be used from the command

line or using an integrated development environment like Xcode or Guile.

http://sourceware.org/gdb/download/onlinedocs/gdb/index.html



gprof

If your code isn’t as fast as you’d hoped, it might be worth profiling

it. The GNU Profiler (gprof) will tell you which parts of your

program are the slowest so that you can tune the code in the most

appropriate way. gprof lets you compile a modified version of

your program that will dump a performance report when it’s

finished. Then the gprof command-line tool will let you analyze

the performance report to track down the slow parts of your code.

http://sourceware.org/binutils/docs-2.22/gprof/index.html



gcov

Another profiling tool is GNU Coverage (gcov). But while gprof

is normally used to check the performance of your code, gcov is

used to check which parts of your code did or didn’t run. This is

important if you’re writing automated tests, because you’ll want to

be sure that your tests are running all of the code you’re expecting

them to.

http://gcc.gnu.org/onlinedocs/gcc/Gcov.html



550   appendix i

www.it-ebooks.info



leftovers



#9. Creating GUIs

You haven’t created any graphical user interface (GUI) programs in

any of the main chapters of this book. In the labs, you used the

Allegro and OpenCV libraries to write a couple of programs that

were able to display very simple windows. But GUIs are usually

written in very different ways on each operating system.



Linux — GTK

Linux has a number of libraries that are used to create GUI

applications, and one of the most popular is the GIMP toolkit

(GTK+):

http://www.gtk.org/

GTK+ is available on Windows and the Mac, as well as Linux,

although it’s mostly used for Linux apps.



Windows

Windows has very advanced GUI libraries built-in. Windows

programming is a really specialized area, and you will probably

need to spend some time learning the details of the Windows

application programming interfaces (APIs) before you can easily build

GUI applications. An increasing number of Windows applications

are written in languages based on C, such as C# and C++. For an

online introduction to Windows programming, see:

http://www.winprog.org/tutorial/



The Mac — Carbon

The Macintosh uses a GUI system called Aqua. You can create

GUI programs in C on the Mac using a set of libraries called

Carbon. But the more modern way of programming the Mac is

using the Cocoa libraries, which are programmed using another

C-derived language called Objective-C. Now that you’ve reached the

end of this book, you’re in a very good position to learn Objective-C.

Here at Head First Labs, we love the books and courses on Mac

programming available at the Big Nerd Ranch:

http://www.bignerdranch.com/



you are here 4   551



www.it-ebooks.info



reference material



#10. Reference material

Here’s a list of some popular books and websites on C programming.

Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language

(Prentice Hall; ISBN 978-0-131-10362-7)

This is the book that defined the original C programming language, and

almost every C programmer on Earth has a copy.

Samuel P. Harbison and Guy L. Steele Jr., C: A Reference Manual

(Prentice Hall; ISBN 978-0-130-89592-9)

This is an excellent C reference book that you will want by your side as

you code.

Peter van der Linden, Expert C Programming

(Prentice Hall; ISBN 978-0-131-77429-2)

For more advanced programming, see Peter van der Linden’s excellent book.

Steve Oualline, Practical C Programming

(O’Reilly; ISBN 978-1-565-92306-5)

This book outlines the practical details of C development.



Websites

For standards information, see:

http://pubs.opengroup.org/onlinepubs/9699919799/

For additional C coding tutorials, see:

http://www.cprogramming.com/

For general reference information, see:

http://www.cprogrammingreference.com/

For a general C programming tutorial, see:

http://www.crasseux.com/books/ctutorial/



552   appendix i

www.it-ebooks.info



ii c topics



Revision roundup



Ever wished all those great C facts were in one place?

This is a roundup of all the C topics and principles we’ve covered in the book. Take a look

at them, and see if you can remember them all. Each fact has the chapter it came from

alongside it, so it’s easy for you to refer back if you need a reminder. You might even want

to cut these pages out and tape them to your wall.



this is an appendix   553



www.it-ebooks.info



basics



CHAPTER 1

CHAPTER 1



#include includes external

code for things like input and

output.



switch statements efficiently

check for multiple values of a

variable.



CHAPTER 1



CHAPTER 1



You can combine conditions

together with && and ||.



Block statements are

surrounded by { and }.



Every program needs a main

function.



CHAPTER 1



CHAPTER 1



if statements run code if

something is true.



CHAPTER 1



Simple statements are

commands.



CHAPTER 1



Basics



Your source files should have a

name ending in .c.



554   appendix ii

www.it-ebooks.info



while repeats code as long as a

condition is true.



for loops are a more compact

way of writing loops.



CHAPTER 1



CHAPTER 1



CHAPTER 1



count++ means add 1 to count.



CHAPTER 1



You can use the && operator on

the command line to only run

your program if it compiles.



CHAPTER 1



CHAPTER 1



CHAPTER 1



You need to compile your C

program before you run it.



CHAPTER 1



CHAPTER 1



revision roundup



gcc is the most popular C

compiler.



-o specifies the output file.



count-- means subtract 1

from count.



do-while loops run code at

least once.



you are here 4   555



www.it-ebooks.info



pointers



CHAPTER 2



A char pointer variable x is

declared as char *x.



Initialize a new array with a

string, and it will copy it.



CHAPTER 2



&x is called a pointer to x.



&x returns the address of x.



CHAPTER 2



Array variables can be used as

pointers.



CHAPTER 2



CHAPTER 2 CHAPTER 2



CHAPTER 2



CHAPTER 2 CHAPTER 2



Pointers and memory



fgets(buf, size, stdin) is a

simpler way to enter text.



scanf(“%i”, &x) will allow a user

to enter a number x directly.



Read the contents of an

address a with *a.



Local variables are stored on

the stack.



556   appendix ii

www.it-ebooks.info



revision roundup



CHAPTER 2.5

CHAPTER 2.5



strstr(a, b) will return the

address of string b in string a.



strcat() concatenates two

strings together.



strcpy() copies one string to

another.



The string.h header contains

useful string functions.



You create an array of arrays

using char strings [...][...].



CHAPTER 2.5



An array of strings is an array

of arrays.



CHAPTER 2.5



Literal strings are stored in

read-only memory.



CHAPTER 2.5



CHAPTER 2.5



CHAPTER 2.5 CHAPTER 2.5 CHAPTER 2.5 CHAPTER 2



Strings



strcmp() compares two strings.



strchr() finds the location of

a character inside a string.



strlen() finds the length of a

string.

you are here 4   557



www.it-ebooks.info



data streams



You can create custom data

streams with fopen(“filename”,

mode).



The Standard Output goes to

the display by default.



CHAPTER 3



CHAPTER 3

CHAPTER 3



The Standard Error is a

separate output intended for

error messages.



CHAPTER 3



The Standard Input reads

from the keyboard by default.



CHAPTER 3



CHAPTER 3



C functions like printf() and

scanf() use the Standard

Output and Standard Input to

communicate.



CHAPTER 3



CHAPTER 3



Data streams



558   appendix ii

www.it-ebooks.info



You can change where the

Standard Input, Output, and

Error are connected to using

redirection.



You can print to the Standard

Error using fprintf(stderr,...).



The mode can be “w” to write,

“r” to read, or “a” to append.



Command-line arguments are

passed to main() as an array of

string pointers.



CHAPTER 3



CHAPTER 3



revision roundup



The getopt() function makes it

easier to read command-line

options.



you are here 4   559



www.it-ebooks.info



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

#7. More on make

Tải bản đầy đủ ngay(0 tr)

×