{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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 Lecture 19 1 CMSC 212 November 3, 2009 Last time circle6 Section 10.9 (Bryant & O'Hallaron) ways to make heaps safer nonstandard gcc facilities for heap inspection and debugging circle6 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 circle6 Chapter 14, The preprocessor preprocessor basics Reading circle6 Read Chapter 16 in Reek (Pointers on C) 3 CMSC 212 Chapter 14, The Preprocessor, con't. 4 CMSC 212
Image of page 1

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

View Full Document Right Arrow Icon
File inclusion circle6 #include <libraryheaderfile.h> and #include "file.h" work as described earlier circle6 What if file.h includes another file? 5 CMSC 212 the preprocessor can handle this circle6 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; } Struct2; struct3.h: #include "struct.h" typedef struct { float x; Struct y; } Struct3; 6 CMSC 212 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. circle6 See the example on the previous slide in the 212public/examples directory; you can run the preprocessor on it circle6 Solution- struct.h becomes: #if !defined(STRUCT_H) #define STRUCT_H 7 CMSC 212 (all the previous contents of struct.h appear here) #endif circle6 This is usually done with all header files so they can be included anywhere in any order without problems File inclusion, con't. circle6 Consider again when one header file includes another circle6 What would dependencies in a makefile look like? circle6 Note: 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 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) #include "file1.h" definitions and prototypes here #endif main.c: #include "file2.h" int main() { lots of code here }
Image of page 2
The #define preprocessor directive circle6 Syntax: #define name replacement-text circle6 Its most common use is for defining symbolic constants – example: #define MAX_TABLE_SIZE 1024 circle6 One of the C naming conventions is that it's good style to use all uppercase letters for preprocessor-defined symbols 9 CMSC 212 this is not required by the preprocessor, but makes it easier for
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern