1
Introduction to C in Linux/Unix
COMP 1002/1402
Writing a Novel
Book
(Novel)
Process
Determine ideas Write book Contact publisher Editing
Story features
(Mystery, metaphors)
Book language
(English, French)
Introduction to C in Linux/Unix COMP 1002/1402 Writing a Novel - - PDF document
Introduction to C in Linux/Unix COMP 1002/1402 Writing a Novel Process Determine ideas Story features Write book (Mystery, Contact publisher metaphors) Editing Book (Novel) Book language (English, French) 1 Creating a program
1
Book
(Novel)
Process
Determine ideas Write book Contact publisher Editing
Story features
(Mystery, metaphors)
Book language
(English, French)
2
Application Program Software Engineering
(process)
Application Smarts
(algorithms, data structures)
Coding
(high level language C)
– Machine code – Assembly language
– Procedural language – Object Oriented
push ebx push esi push edi mov dword ptr [ebp-18h],esp mov eax,94h call 00410C30 mov dword ptr [ebp-30h],esp psquares=squares; /*fill array with squares of numbers*/ for(i=0;i<1000;i++) *(psquares++)=i*i; printf("\nWIDTH : "); scanf("%d",&WIDTH); printf("\nHEIGHT : "); scanf("%d",&HEIGHT);
3
circuit
– Add, subtract, shift bits, load bits into cpu…
push ebx push esi push edi mov dword ptr [ebp-18h],esp mov eax,94h call 00410C30 mov dword ptr [ebp-30h],esp
psquares=squares; /*fill array with squares of numbers*/ for(i=0;i<1000;i++) *(psquares++)=i*i; printf("\nWIDTH : "); scanf("%d",&WIDTH); printf("\nHEIGHT : "); scanf("%d",&HEIGHT);
4
5
– output :object code. – object code is essentially machine code + unresolved references.
linker.
– Output : machine code or load module.
– Source code, – object code and – load module (machine code). The load module is executable.
6
7
– Removes comments – Substitutes constants with values – Inserts files indicated by #include – Follows other directives
8
9
– Single stage process – Two stage process
– Implies two stage process – (Preprocess, compile and assemble) then link later
Sigma01> gcc hello.c
10
Sigma01> gcc -o hello hello.c
Sigma01> ./hello
Sigma01> hello
11
Sigma01> gcc –g –o hello hello.c
12
13
Sigma01> hello there john peter smith
Sigma01> gcc –g -o hello hello.c
14
15
Starting program: /home/John/Code/hello Program received signal SIGSEGV, Segmentation fault. 0x4007f2c0 in strcpy () from /lib/libc.so.6
(gdb) backtrace
#0 0x4007f2c0 in strcpy () from /lib/libc.so.6 #1 0xbffffc4c in __DTR_END__ () from /lib/libc.so.6 #2 0x80485f6 in __libc_start_main () from /lib/libc.so.6 #3 0x80485f6 in ?? () Cannot access memory at address 0xe853.
(gdb)
16
(gdb) break 3
Breakpoint 1 at 0x80788e1: file hello.c, line 3.
(gdb) run
The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/John/Code/hello Breakpoint 1, main (argc=1,argv=0xbffffc4c) at hello.c:3 3 {
Cannot access memory at address 0xe853.
17
– Multiple headers – Multiple object files – Worldwide source contribution – Integrated debugging symbols
18
19
20
21
22
hello : hello1.o hello2.o hello3.o gcc -o hello hello1.o hello2.o hello3.o # generate object file for hello1.c hello1.o: hello1.c gcc -c hello1.c # generate object file for hello2.c hello2.o: hello2.c gcc -c hello2.c # generate object file for hello3.c hello3.o: hello3.c gcc -c hello3.c
hello : hello1.o hello2.o hello3.o
23
gcc -o hello hello1.o hello2.o hello3.o
24
Here are some sources re. Linux : http://humbolt.geo.uu.nl/Linux-MM/ http://members.aa.net/~swear/pedia/index.html. http://www.mainmatter.com/ http://www.linuxdoc.org/ http://www.linuxbox.com/~taylor/4ltrwrd/ http://www.stuwww.kub.nl/people/b.vannunen/linux- man.php3 http://www.linuxdoc.org/nlm/