cp_1_lect_19 - Writing C Programs A programmer uses a text...

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

View Full Document Right Arrow Icon
5/10/10 Writing C Programs A programmer uses a text editor to create or modify files containing C code. Code is also known as source code . A file containing source code is called a source file . After a C source file has been created, the programmer must invoke the C compiler before the program can be executed ( run ).
Background image of page 1

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

View Full DocumentRight Arrow Icon
5/10/10 Invoking the cc Compiler At the $ prompt, type $ cc pgm.c where pgm.c is the C program source file. The Result : a.out If there are no errors in pgm.c, this command produces an executable file, which is one that can be executed (run). The cc compiler names the executable file a.out . To execute the program, at the prompt,
Background image of page 2
5/10/10 3 Stages of Compilation Stage 1: Preprocessing Performed by a program called the preprocessor Modifies the source code (in RAM) according to preprocessor directives (preprocessor commands ) embedded in the source code 5 Strips comments and white space from the code 5 The source code as stored on disk is not modified.
Background image of page 3

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

View Full DocumentRight Arrow Icon
5/10/10 3 Stages of Compilation Stage 2: Compilation Performed by a program called the compiler Translates the preprocessor-modified source code into object code (machine code) Checks for syntax errors and warnings Saves the object code to a disk file, if instructed to do so (we will not do this). o If any compiler errors are received, no object code file will be generated.
Background image of page 4
5/10/10 3 Stages of Compilation Stage 3: Linking Combines the program object code with other object code to produce the executable file. 5 The other object code can come from the Run-Time Library , other libraries, or object files that you have created. 5 Saves the executable code to a disk file. On the Linux system, that file is called a.out . o If any linker errors are received, no executable
Background image of page 5

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

View Full DocumentRight Arrow Icon
5/10/10 Learning a Language Analogy between learning English and Learning C Alphabet s Words Sentence s Paragraph Steps in learning English Alphabets Digits Special Symbols Constants Variables Keywords Instruction s Program Steps in learning C
Background image of page 6
5/10/10 The C Character Set Alphabets: A, B, C, …Z and a, b, c, d, …z Digits: 0, 1, 2, …9 Special Symbols: ~ ! @ # % ^ & * ( ) _ - + = | \ { } [ ] : ; < > , . ? /
Background image of page 7

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

View Full DocumentRight Arrow Icon
5/10/10 C Tokens Smallest individual unit
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 28

cp_1_lect_19 - Writing C Programs A programmer uses a text...

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

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