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

2019.10.15_revised.pdf - Quote of the Day ‣"Programming...

This preview shows page 1 - 15 out of 90 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 note: terminology not necessarily consistent across sources or even within a single source declaration : the name of the variable is given, the type of the variable is given, and storage is reserved/allocated example int debugflag; main() { int i; ... } compiler allocates or arranges for storage 8
Image of page 8
Aside: Definition vs. Declaration definition : the variable is named and typed, but no storage is allocated example •typedef -typedef int Length; - a type is associated with name Length , but no storage is allocated -typedef int Length; // this is a definition ... Length maxlen; // this is a declaration 9
Image of page 9
Aside: Definition vs. Declaration terminology is different in case of functions declaration is function prototype (header), but no body definition is function prototype plus body example: declaration of power() in example_25 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 declaration, and persists until the end of the block in which it was declared. 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 declared outside of any function are global to the file in which they are declared, but also local to that file •default •see previous example to access global variables declared in another file, use extern specifier •makes the variable are global within the file 13
Image of page 13
Aside: External Linkage necessary when source code is split across multiple source files use extern storage class specifier e.g.
Image of page 14
Image of page 15

You've reached the end of your free preview.

Want to read all 90 pages?

  • Spring '14