37_pdfsam_cs2022_lectures

37_pdfsam_cs2022_lectures - Multiple source files Breaking...

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

View Full Document Right Arrow Icon
Multiple source files Breaking up program into several source files Unlike Java, it doesn’t require you to do this How you break up the program is up to you To do this, Put the code for a function in exactly one file Put a function prototype in any file that uses the function Advantages Organization No need to recompile unchanged files: save time
Background image of page 1

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

View Full DocumentRight Arrow Icon
Example: multiple source files #include <stdio.h> int power(int base, int exp); int cube(int base); int main(void) { printf(“%d\n”, power(5, 3)); printf(“%d\n”, cube(10)); return 0; } int power( int base, int exp ) { int i, p = 1; for( i = 1; i <= exp; i++ ) p *= base; return p; } int power(int base, int exp); int cube(int base) { return power(base, 3); } main.c power.c cube.c
Background image of page 2
A C header file contains function prototypes But does not contain implementation code Files have extension .h by convention e.g. a snippet of stdio.h: void perror(char *); int printf(char *, . ..); int putc(int, 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
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/10/2010 for the course CS 2022 at Cornell.

Page1 / 6

37_pdfsam_cs2022_lectures - Multiple source files Breaking...

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

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