Presentation is loading. Please wait.

Presentation is loading. Please wait.

First Compilation Rudra Dutta CSC 230 - Spring 2007, Section 001.

Similar presentations


Presentation on theme: "First Compilation Rudra Dutta CSC 230 - Spring 2007, Section 001."— Presentation transcript:

1 First Compilation Rudra Dutta CSC 230 - Spring 2007, Section 001

2 Copyright Rudra Dutta, NCSU, Spring, 20072 Command Line Interface to interact with UNIX Access to commands for several commonly used tasks ls cat more cc gcc man

3 Copyright Rudra Dutta, NCSU, Spring, 20073 Hello program #include main () { int i; /* light-years beyond "hello world" */ printf ("Hello, universe!\n"); /* it even loops */ for (i=0; i<3; i++) { printf ("\t%d\n", i); }

4 Copyright Rudra Dutta, NCSU, Spring, 20074 File and Program Flow File - basic unit of compilation / translation – Broken into tokens – Parsed by rules of syntax – Composed of code blocks Generally delineated by braces Program Flow – Sequence of instructions executed by process

5 Copyright Rudra Dutta, NCSU, Spring, 20075 Object-oriented vs. Procedural

6 Copyright Rudra Dutta, NCSU, Spring, 20076 Stages of Compilation hello.c abcbacbb cbcababc bcbabcbc abbacbc #include cbcababc 0100100 1010100 1010010 1001010 hello.c hello.o a.out Source Intermediate Target preprocess compile link

7 Copyright Rudra Dutta, NCSU, Spring, 20077 Macros Defined and undefined within translation unit (file) Processed by pre-processor – Therefore before language interpretation begins Has own tokenizer

8 Copyright Rudra Dutta, NCSU, Spring, 20078 Header and Library Files Standard header files in standard locations User-generated header files in current directory – Or pointed to by path Often functions made available by header is in separate library – In standard locations All these can be overridden by command line options

9 Copyright Rudra Dutta, NCSU, Spring, 20079 Declaration and Definition Declaration - assertion that entity exists, reserves place in symbol table (namespace) Definition - actually provides memory and content of memory for entity For variables, very often the definition also serves as the declaration – And is often called “declaration” Functions are also declared and defined – Frequently separately object and lvalue Entity that occupies memory Expression that provides location in memory

10 Copyright Rudra Dutta, NCSU, Spring, 200710 Memory The C programmer needs several views of memory Physical memory of machine - long sequence of x-bit words Virtual memory - long sequence of bytes – Numbered from 0 to … – Address of the byte Programs stay in memory when running – Memory locations hold instructions Memory space of a process – Some part of the virtual memory virtualized by the OS as “entire memory” for process

11 Copyright Rudra Dutta, NCSU, Spring, 200711 Heap and Stack Stack - the part of the process memory where the program resides Heap - an “amorphous” place of memory where program can explicitly obtain chunks of memory

12 Copyright Rudra Dutta, NCSU, Spring, 200712 Use of Stack Declaration of variables creates memory objects on stack Functions themselves also on stack main () { int i; /* light-years beyond "hello world" */ printf ("Hello, universe!\n"); /* it even loops */ for (i=0; i<3; i++) { printf ("\t%d\n", i); }

13 Next: Another Function

14 Copyright Rudra Dutta, NCSU, Spring, 200714 Compute the Square int square (int x) { x *= x; return (x); } Strictly speaking, functions should be declared before being used Definition counts as a declaration, but not always possible to define before use Use gcc -Wall to see all warnings – Also use -ansi and -pedantic to get good information Another look at stdio.h


Download ppt "First Compilation Rudra Dutta CSC 230 - Spring 2007, Section 001."

Similar presentations


Ads by Google