-
CMPSC 311 - Introduction to Systems Programming
CMPSC 311- Introduction to Systems Programming Module: Build - - PowerPoint PPT Presentation
CMPSC 311 - Introduction to Systems Programming
CMPSC 311 - Introduction to Systems Programming Page
2
mcdaniel@ubuntu:~/siis/courses/cmpsc311-f13/docs/assign/assign2$ cat numbers.txt 313.11 45.64 9.50 113.89 mcdaniel@ubuntu:~/siis/courses/cmpsc311-f13/docs/assign/assign2$ cat numbers.txt | sort -n 9.50 45.64 113.89 313.11 mcdaniel@ubuntu:~/siis/courses/cmpsc311-f13/docs/assign/assign2$
CMPSC 311 - Introduction to Systems Programming Page
3
mcdaniel@ubuntu:~/siis/courses/cmpsc311-f13/docs/assign/assign2$ cat inputs.txt | ./cmpsc311-f13-assign2 ********************************************************************* Received and computed values 9.50 45.64 313.11 113.89 81.56 250.00 11.90 469.98 313.11 4.68 34.33 8013.55 -10.15 11.50 88.00 10 46 313 114 82 250 12 470 313 5 34 8014 -10 12 88 The largest element of the float array is 8023.75 The largest element of the int array is 8014 ********************************************************************* Altered values ....
CMPSC 311 - Introduction to Systems Programming Page
4
CMPSC 311 - Introduction to Systems Programming Page
5
CMPSC 311 - Introduction to Systems Programming Page
6
CMPSC 311 - Introduction to Systems Programming Page
7
CMPSC 311 - Introduction to Systems Programming Page
7
CMPSC 311 - Introduction to Systems Programming Page
7
CMPSC 311 - Introduction to Systems Programming Page
8
CMPSC 311 - Introduction to Systems Programming Page
8
CMPSC 311 - Introduction to Systems Programming Page
8
CMPSC 311 - Introduction to Systems Programming Page
9
CMPSC 311 - Introduction to Systems Programming Page
10
CMPSC 311 - Introduction to Systems Programming Page
11
#define NUMBER_ENTRIES 15 ... int main( void ) { // Declare your variables here float myFloats[NUMBER_ENTRIES]; // Read float values for ( i=0; i<NUMBER_ENTRIES; i++ ) { scanf( "%f", &myFloats[i] ); }
CMPSC 311 - Introduction to Systems Programming Page
12
/* Defining a function to swap pairs of integers */ #define swap(x,y) {int temp=x; x=y; y=temp;} int main( void ) { // Declare your variables here int i = 1, j =2; ... swap(i,j);
CMPSC 311 - Introduction to Systems Programming Page
13
#define DEFINED ... #if 0 /* This does not get compiled */ #else /* This does get compiled */ #endif #ifdef UNKNOWNVALUE /* This does not get compiled */ #else /* This does get compiled */ #endif #ifndef DEFINED /* This does not get compiled */ #else /* This does get compiled */ #endif /* A quick way to comment out code, as typically used in doing debugging and unit testing */ int main( void ) { // Declare your variables here float myFloats[NUMBER_ENTRIES]; #if 0 // Read float values for ( i=0; i<NUMBER_ENTRIES; i++ ) { scanf( "%f", &myFloats[i] ); } // Show the list of unsorted values printCharline( '*', 69 ); printf( "Received and computed\n" ); #endif ...
CMPSC 311 - Introduction to Systems Programming Page
14
CMPSC 311 - Introduction to Systems Programming Page
15
CMPSC 311 - Introduction to Systems Programming Page
16
CMPSC 311 - Introduction to Systems Programming Page
16
CMPSC 311 - Introduction to Systems Programming Page
17
sample sample.o support.o
CMPSC 311 - Introduction to Systems Programming Page
18
sample : sample.o support.o gcc sample.o support.o -o sample sample.o : sample.c support.h gcc -c -Wall -I. sample.c -o sample.o support.o : support.c support.h gcc -c -Wall -I. support.c -o support.o
sample sample.o support.o sample.c support.h support.c
CMPSC 311 - Introduction to Systems Programming Page
19
CMPSC 311 - Introduction to Systems Programming Page
19
sample sample.o support.o sample.c support.h support.c
CMPSC 311 - Introduction to Systems Programming Page
19
sample sample.o support.o sample.c support.h support.c sample sample.o support.o sample.c support.h support.c
CMPSC 311 - Introduction to Systems Programming Page
19
sample sample.o support.o sample.c support.h support.c sample sample.o support.o sample.c support.h support.c sample sample.o support.o sample.c support.h support.c
CMPSC 311 - Introduction to Systems Programming Page
19
sample sample.o support.o sample.c support.h support.c sample sample.o support.o sample.c support.h support.c sample sample.o support.o sample.c support.h support.c sample sample.o support.o sample.c support.h support.c
CMPSC 311 - Introduction to Systems Programming Page
20
CMPSC 311 - Introduction to Systems Programming Page
21
sample : $(OBJECT_FILES) $(CC) $^ -o $@ sample.o : sample.c support.h $(CC) $(FLAGS) sample.c -o $@ support.o : support.c support.h $(CC) $(FLAGS) support.c -o $@
CMPSC 311 - Introduction to Systems Programming Page
22
.SUFFIXES: .c .o .c.o: $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $< sample.o : sample.c support.h support.o : support.c support.h
CMPSC 311 - Introduction to Systems Programming Page
23
# # Sample Makefile # Variables CC=gcc LINK=gcc CFLAGS=-c -Wall -I. OBJECT_FILES=sample.o support.o # Suffix rules .SUFFIXES: .c .o .c.o: $(CC) -c $(CFLAGS) -o $@ $< # Productions sample : $(OBJECT_FILES) $(LINK) $(OBJECT_FILES) -o $@ # Dependancies sample.o : sample.c support.h support.o : support.c support.h % make gcc -c -c -Wall -I. -o sample.o sample.c gcc -c -c -Wall -I. -o support.o support.c gcc sample.o support.o -o sample %