2 - C Programming Language (1) 1 Outline Samplecodes...

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

View Full Document Right Arrow Icon
1 C Programming Language (1)
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline Sample codes Introduction Compiler drivers Assembly code and object code Suggested reading 1.1 1.2
Background image of page 2
3 “Hello world” example 1  #inc lude  <s tdio .h> 2 3  int m a in() 4  { printf(" he llo , wo rld\n" ); 6 } File inclusion Standard Library Header file
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 File Inclusion and Macro Substitution a.c #include “b.h” main() {       return i+j ; } b.h #define i  100 int  j ; Macro Substitution int j ; main() { return 100 + j ; }
Background image of page 4
5 File Inclusion and Macro Substitution #include  “filename” #include  <filename> #define forever  for(;;)  /* infinite loop */ #define  square(x)   (x)*(x)
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Formatted Output - Printf int  printf(char* format, arg1, arg2, …) printf(“%d, %d\n”, i, j) ; %d, %i     decimal number %o           octal number(without a leading zero) %x, %X   hexadecimal number %c   single charater
Background image of page 6
7 The Context of a Compiler (gcc) Source program (text) hello. c Preprocessor (cpp) Modified source program (text) hello. i Assembly program (text) Compiler (cc1) hello. s Assembler (as) Relocatable object program (binary) hello. o Linker (ld) Executable object program (binary) hell o
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 “Hello world” example 1  #inc lude  <s tdio .h> 2 3  int m a in() 4  { printf(" he llo , wo rld\n" ); 6 } File inclusion Standard Library Header file
Background image of page 8
9 The Hello Program Source program Created by editor and saved as a text file Begins life as a high-level C program Can be read and understand by human beings  The individual C statements must be translated by compiler  drivers So that the hello program can run on a computer system
Background image of page 9

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

View Full DocumentRight Arrow Icon
Text File # i n c l u d e <sp> < s t d i o . 35 105 110 99 108 117 100 101 32 60 115 116 100 105 111 46 h > \ n \ n i n t <sp> m a i n ( ) \ n { 104 62 10 10 105 110 116 32 109 97 105 110 40 41 10 123 \ n <sp> <sp> <sp> <sp> p r i n t f ( " h e 10 32 32 32 32 112 114 105 110 116 102 40 34 104
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2011 for the course CS 000 taught by Professor Jing during the Fall '10 term at Fudan University.

Page1 / 35

2 - C Programming Language (1) 1 Outline Samplecodes...

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

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