03-make - CPE 357 - Systems Programming Spring 2009, Day 3...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: CPE 357 - Systems Programming Spring 2009, Day 3 Multi-file Projects Last Modified: Mon Sep 28 11:24:13 PDT 2009 Will be: identifiers, scope and linkage macros makefiles filters Header files group at top (legal but undesirable to have internal externs) (avoids need for internal 'extern') declarations: variables functions types macros some of these should be shared. Best to do it once. Identifiers: Namespaces: one per class of identifiers: - objects (data), functions, typedef names, enum constants. - labels (which we don't use) - tags (struct union enum) - fields/members of each struct or union individually. From K&R: lexical scope (or just scope) is the region of the program text in which the identifier's characterstics are understood. Second, the scope associated with objects and functions with external linkage, which determines the connections between identifiers in separately compiled translation units. external declarations: scope begins at the end of the declarator, persists to the end of the translation unit. parameters: function body locals: end of declarator to end of block tags: declaration to end (of translation unit or block) linkage: if internal, all in the unit refer to the same thing (and must agree). if external, all refer to the same thing and it's shared by the entire program. the first declaration specifies linkage. It's internal if it's static; external otherwise. locals: no linkage unless extern. matches linkage of an existing external declaration, or has external linkage. globals (external to all functions) known to K&R as external variables K&R says they can be used to communicate between functions. This is now pretty universally viewed with suspicion if not outright disgust. They do have the charm that their values persist with the program. A global must be defined EXACTLY once; this will be outside any function. This sets aside storage. And determines linkage. Declaration: via "extern" in each function, or by its appearing earlier. "In fact, common practice is to place definitions of all external variables at the beginning of the source file, and then omit all extern declarations" We will follow that practice. This eliminates "internal" extern. shadowing Makefiles Dependency (make rules) Derivation (make rules) Makefile.simple CC=gcc LD=gcc CFLAGS=-Wall --std=c99 -pedantic LDFLAGS= Makefile.target use of tab Macros abs sum Ifdef (debug) see my class/Obfuscate/ob/clear6.c in obfuscate If possible: filters example: filter in examples folder LAB: Write a program to take MAX and MIN of two inputs use a macro put macro in another file Alternative: ABS SIGNUM vim: set sts=2 sw=2 ai et : ...
View Full Document

This note was uploaded on 10/12/2009 for the course CPE 357 taught by Professor O'gorman during the Spring '09 term at Cal Poly.

Ask a homework question - tutors are online