DOC PREVIEW
UW CSE 303 - Lecture Notes

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

10/23/20091David Notkin  Autumn 2009  CSE303 Lecture 11“Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration.”Stan Kelly-Bootlehttp://www.devtopics.com/101-great-computer-programming-quotes/Upcoming scheduleCSE303 Au09 2Today10/23Monday10/26Wednesday10/28Friday10/30Monday11/2Finish-up WednesdaySome specifics for HW3Social implications FridayMemory managementMidtermreviewMidtermWednesday: after class question• Paraphrase: “If I overwrite memory outside the bounds of my process, can I hurt other processes or my computer?”• No, you can’t• Indeed, although you can do almost anything within your process – and can make your life miserable doing so – Unix keeps everything you do within your own process (well, close enough)• Indeed, that’s why you get a segfault if you access memory outside of your virtual address space• So, you can destroy your process, but other processes and your computer remain safeCSE303 Au09 3Pointer: a memory address referring to another valuetype* name; // declaretype* name = address; // declare/initializeint x = 42;int* p;p = &x; // p stores address of xprintf("x is %d\n", x); // x is 42printf("&x is %p\n", &x); // &x is 0x0022ff8cprintf("p is %p\n", p); // p is 0x0022ff8cDereferencing: access the memory referred to by a pointer*pointer // dereference*pointer = value; // dereference/assignint x = 42;int* p;p = &x; // p stores address of x*p = 99; // go to the int p refers to; set to 99printf("x is %d\n", x);Output: x is 99* vs. &• many students get * and & mixed up– & references (ampersand gets an address)– * dereferences (star follows a pointer)int x = 42;int* y = &x;printf("x is %d \n", x); // x is 42printf("&x is %p\n", &x); // &x is 0x0022ff8cprintf("y is %p\n", y); // y is 0x0022ff8cprintf("*y is %d \n", *y); // *y is 42printf("&y is %p\n", &y); // &y is 0x0022ff88• What is *x ?10/23/20092L-values and R-values• L-value: Suitable for being on left-side of an =assignment -- a valid memory address to store into• R-value: Suitable for right-side of an = assignmentint x = 42;int* p = &x;• L-values : x or *p (store into x), p (changes what ppoints to)• not &x, &p, *x, *(*p), *12• R-values : x or *p, &x or p, &p• not &(&p), &42Pass-by-value: copy parameters' values• Cannot change the original (“actual”) parameter variableint main(void) {int a = 42, b = -7;swap(a, b);printf("a = %d, b = %d\n", a, b);return 0;}void swap(int a, int b) {int temp = a;a = b;b = temp;}Pass-by-reference: point to parameters• Can change the actual parameter variable using the “formal”int main(void) {int a = 42, b = -7;swap(a, b);printf("a = %d, b = %d\n", a, b);return 0;}void swap(int a, int b) {int temp = a;a = b;b = temp;}#1 to know for HW3: arguments to main#include <stdio.h>#include <string.h>int main(int argc, char *argv[]) {printf("%s#%d#%d\n",argv[1] // print 1stargument as stringstrlen(argv[1]), // show it’s a stringatoi(argv[1])+1); // convert it to an int}------------------------------------------------$ a.out 546546#3#547$CSE303 Au09 10#2 to know for HW3• printf("%4d%2d%3.1f%%\n”…)• Printing fixed-width field• Printing fixed number of decimal places• Printing %CSE303 Au09 11#3 to know for HW3• Input functions to consider (depending on your approach)– scanf – read and convert values– getchar – read next character• Depending on your approach, you may need to convert among data types [I didn’t need any of these, except for one atoi]– atoi – ascii to int– sscanf – same as scanf, but from a string instead of a file (stream)– sprintf – same as printf, but into a string instead of to a file (stream)CSE303 Au09 1210/23/20093#4 to know for HW3• How to handle reaaallllllllllllllyyyyyyyyyyyyyyy long integer entries?22953686867719691230002707821868552601124472329079231 30762542250301270692051460539586166927291732754961 2992740239799128648962783773417918638518829638222731454464847298035401831018301678756237887945334412167793239564780647927552813573378126620390479441956306440723 644953277318876935397385586910668391033885673004492 58645563317564309847334478714939069495243200674793 4870509135523888277884290923005671214081346015789923332 1545241701177578785195104730956315938884094630980713232 5354288503961524527117435531562370433428477356819923309• Hint: think about the whole problem – not just how to handle input – before you code – it can be easier than you think, unless you don’t think about itCSE303 Au09 13Ethics• Definition?CSE303 Au09 14“the rules of conduct recognized in respect to a particular class of human actions or a particular group, culture, etc.” ethics. Dictionary.com. The American Heritage® Dictionary of the English Language, Fourth Edition. Houghton Mifflin Company, 2004. http://dictionary.reference.com/browse/ethics (accessed: October 23, 2009).Codes of ethics• http://ethics.iit.edu/ -- just two categories in their lists are– Sports and Athletics• American Football Coaches Association• Australian Sports Commission• Canadian Curling Association• Canadian Soccer Association• Club Cycliste Baconsfield• National Association of Sports Officials• National Basketball Association• United States Olympic Committee– Fraternal Social Organizations• Brookline Bird Club• Gamma Beta Phi• National Speleogical Society• Universal Autograph Collectors ClubCSE303 Au09 15Why have codes of ethics?• Aren’t laws enough?• Isn’t personal commitment enough?• Aren’t company policies enough?• …CSE303 Au09 16Why have engineering codes of ethics?• And why have software engineering codes of ethics?CSE303 Au09 17Software Engineering Code ofEthics and Professional Practice [short version]• In accordance with their commitment to the health, safety, and welfare of the public, software engineers shall adhere to the following eight Principles:1. Public. Software engineers shall act consistently with the public interest.2. Client and employer. Software engineers shall act in a manner that is in the best interests of their client and employer, consistent with the public interest.3. Product. Software engineers shall ensure that their products and related modifications meet the highest professional standards possible.4. Judgment. Software engineers shall


View Full Document

UW CSE 303 - Lecture Notes

Documents in this Course
Profiling

Profiling

11 pages

Profiling

Profiling

22 pages

Profiling

Profiling

11 pages

Testing

Testing

12 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?