chapter02 - COP 3275: Chapter 02 Jonathan C.L. Liu, Ph.D....

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

View Full Document Right Arrow Icon
COP 3275: Chapter 02 Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA
Background image of page 1

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

View Full DocumentRight Arrow Icon
Program: Printing a Pun #include <stdio.h> int main(void) { printf("To C, or not to C: that is the question.\n"); return 0; } This program might be stored in a file named pun.c . The file name doesn’t matter, but the .c extension is often required. 2
Background image of page 2
Compiling and Linking Before a program can be executed, three steps are usually necessary: Preprocessing. The preprocessor obeys commands that begin with # (known as directives ) Compiling. A compiler translates then translates the program into machine instructions ( object code ). Linking. A linker combines the object code produced by the compiler with any additional code needed to yield a complete executable program. The preprocessor is usually 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Compiling and Linking Using cc To compile and link the pun.c program under UNIX, enter the following command in a terminal or command-line window: % cc pun.c The % character is the UNIX prompt. Linking is automatic when using cc ; no separate link command is necessary. 4
Background image of page 4
Compiling and Linking Using cc After compiling and linking the program, cc leaves the executable program in a file named a.out by default. The -o option lets us choose the name of the file containing the executable program. The following command causes the executable version of pun.c to be named pun : % cc -o pun pun.c 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
The GCC Compiler GCC is one of the most popular C compilers. GCC is supplied with Linux but is available for many other platforms as well. Using this compiler is similar to using cc : % gcc -o pun pun.c 6
Background image of page 6
Integrated Development Environments An integrated development environment (IDE) is a software package that makes it possible to edit, compile, link, execute, and debug a program without leaving the environment. 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
The General Form of a Simple Program Simple C programs have the form directives int main(void) { statements } 8
Background image of page 8
The General Form of a Simple Program C uses { and } in much the same way that some other languages use words like begin and end . Even the simplest C programs rely on three key language features: Directives Functions Statements 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
Directives Before a C program is compiled, it is first edited by a preprocessor. Commands intended for the preprocessor are called directives. Example: #include <stdio.h> <stdio.h> is a header containing information about C’s standard I/O library. 10
Background image of page 10
Directives Directives always begin with a # character. By default, directives are one line long; there’s no semicolon or other special marker at the end. 11
Background image of page 11

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

View Full DocumentRight Arrow Icon
A function is a series of statements that have been grouped together and given a name. Library functions are provided as part of the C implementation. A function that computes a value uses a
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 60

chapter02 - COP 3275: Chapter 02 Jonathan C.L. Liu, Ph.D....

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

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