2019.10.15.pdf - Quote of the Day ‣"Programming today is a race between software engineers striving to build bigger and better idiotproof programs and

2019.10.15.pdf - Quote of the Day ‣"Programming today is...

This preview shows page 1 - 15 out of 88 pages.

Quote of the Day "Programming today is a race between software engineers striving to build bigger and better idiot- proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning." •Rick Cook 1
Image of page 1
Announcements make-up lab •holiday October 14 •Wednesday, October 16 •S320 sample exams 2
Image of page 2
Announcements BarCamp •"ad-hoc unconference born from the desire for people to share and learn in an open environment" •Saturday, October 19th from 1pm-8pm •Atrium at Innovation Place •more information at 444800262984348/ 3
Image of page 3
Announcements VOTE! in federal election •October 21 4
Image of page 4
Announcements Student Learning Services •series of events for students •example: "Study Strategies for Academic Success" - Wednesday, Oct 16 10:30 – 11:20 Murray Library 102 •more information at eventsRegistration/public/listEvents?currentSystemId=1 5
Image of page 5
Quick review … 6
Image of page 6
Scoping identifiers (variables) are visible only in the block in which they are declared; e.g., 7 ... { int a = 10; int b = 5; printf("%d %d\n", a, b); /* a==10, b==5 */ { int a = 15; printf("%d %d\n", a, b); /* a==15, b==5 */ } printf("%d %d\n", a, b); /* a==10, b==5 */ } ...
Image of page 7
Aside: Definition vs. Declaration declaration : the name of the variable is given, the type of the variable is given, but no storage is allocated example •explicit declaration of external linkage - necessary when source code is split across multiple source files - extern type varName; - compiler told that the actual storage allocation is being done elsewhere; only being told variable name and type 8 source code file 1: source code file 2: int gflag; extern int gflag;
Image of page 8
Aside: Definition vs. Declaration another declaration example •typedef -typedef int Length; - a type is associated with name Length , but no storage is allocated -typedef int Length; // this is a declaration ... Length maxlen; // this is a definition example: declaration of power() in example_25 9
Image of page 9
Aside: Definition vs. Declaration definition : the variable is named and typed, and storage is reserved/allocated example int debugflag; main() { int i; ... } compiler allocates or arranges for storage 10
Image of page 10
On to today’s material … 11
Image of page 11
Scoping usually, the scope of a variable begins at the end of its definition or declaration, and persists until the end of the block in which it was defined. functions are global •to the entire program (across multiple files constituting the program) by default •to just a separately-compiled file - set up by internal linkage (coming up) nesting •cannot have nested functions •can have nested blocks; e.g. previous example 12
Image of page 12
Scoping variables defined outside of any function are global to the file in which they are defined, but also local to that file •default •see previous example to access global variables declared in another file, use extern declaration •makes the variable are global within the file •see example of external linkage earlier can be over-ridden by internal linkage (coming up) 13
Image of page 13
Scoping external static use static
Image of page 14
Image of page 15

You've reached the end of your free preview.

Want to read all 88 pages?

  • Spring '14