lecture19 - Last time Section 10.9 (Bryant & O'Hallaron)...

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

View Full Document Right Arrow Icon
Introduction to Low-Level Programming Concepts CMSC 212 ecture 19 1 CMSC 212 Lecture 19 November 3, 2009 Last time c – ways to make heaps safer – nonstandard gcc facilities for heap inspection and debugging c Chapter 13, Advanced pointer topics – advanced declarations – function pointers and examples 2 CMSC 212 – uses and examples of void pointers – command-line arguments and environment variables c Chapter 14, The preprocessor – preprocessor basics Reading c Read Chapter 16 in Reek (Pointers on C) 3 CMSC 212 Chapter 14, The Preprocessor, con't. 4 CMSC 212
Background image of page 1

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

View Full DocumentRight Arrow Icon
File inclusion c #include <libraryheaderfile.h> and #include "file.h" – work as described earlier hat if ile.h cludes another file? 5 CMSC 212 c What if file.h includes another file? – the preprocessor can handle this c But what if two header files each need to #include a third one? – this is fine, until another file #include 's both of those header files File inclusion example struct.h: typedef struct { float x; double y; } Struct; struct2.h: #include "struct.h" typedef struct { int a; char b; float c; truct2; struct3.h: #include "struct.h" typedef struct { float x; Struct y; } Struct3; 6 CMSC 212 } Struct2; void f(Struct2 s, Struct t); Struct3 g(void); main.c: #include <stdio.h> #include "struct2.h" #include "struct3.h" int main() { Struct2 s2; Struct3 s3; return 0; } File inclusion, con't. c See the example on the previous slide in the 212public/examples directory; you can run the preprocessor on it c Solution- struct.h becomes: #if !defined(STRUCT_H) #define STRUCT_H 7 CMSC 212 (all the previous contents of struct.h appear here) #endif c This is usually done with all header files so they can be included anywhere in any order without problems File inclusion, con't. c Consider again when one header file includes another c What would dependencies in a makefile look like? ote: some people say file2.h: #if !defined(FILE2_H) define FILE2_H file1.h: #if !defined(FILE1_H) #define FILE1_H definitions and prototypes here #endif 8 CMSC 212 c Note: some people say it's better style to have every file explicitly #include all header files with definitions that it uses (if so, main.c would #include file1.h also) #define FILE2_H #include "file1.h" definitions and prototypes here #endif main.c: #include "file2.h" int main() { lots of code here }
Background image of page 2
The #define preprocessor directive c Syntax: #define name replacement-text c Its most common use is for defining symbolic constants – example: #define MAX_TABLE_SIZE 1024
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 11/23/2009 for the course CMSC 212 taught by Professor Staff during the Spring '08 term at Maryland.

Page1 / 7

lecture19 - Last time Section 10.9 (Bryant & O'Hallaron)...

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