DOC PREVIEW
Duke CPS 108 - Dealing with errors

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:

Duke CPS 1087. 1Dealing with errors● How to deal with errors?➤ ignore them➤ end the program (cleanly)➤ print an error message➤ set error flag for others to check (global or not?)➤ exceptions● In C, errno and perror➤ problems?● In C++, exceptions➤ problems?Duke CPS 1087. 2Coping with C instead of C++● Only pass-by-value, no reference parameters void changeIt(int * x) void changeIt(int & x) { { *x = 3; x = 3; } } int val = 13; int val = 13; changeIt(&val); changeIt(val); cout << val << endl; cout << val << endl;● To make an array (allocate and pass back) void fillUp(int **x) { *x = new int[100]; } int * x;what about int *x[] as param? fillUp(&x);java: addres-of operater is evil x[0] = 13;Duke CPS 1087. 3C++ and C-isms● In C++ a struct is a class in which public is default➤ supports everything a class does, including inheritance➤ in C, a struct requires the word struct, typedef often used typedef struct node_s { int value; struct node_s * next; struct node_s * bar; } Node; Node * foo;● pointers to functions: use right-left-right rule (watch parens) void foo(int (*df) (double,double)); typedef int (*iddfunc) (double,double); void foo(iddfunc df);Duke CPS 1087. 4Using the system, dot files● The shell is the program you type commands at➤ different shells: sh, csh, bash, ksh, tcsh➤ use tcsh unless you’re positive you want something else● the shell looks at your PATH environment variable to determinewhere commands you type are found➤ uses directories specified in left-to-right ordersetenv PATH /afs/acpub/project/cps/bin:${PATH}➤ also /bin/sh variable called path (lower case) set differently● .cshrc file, used each time you start a shell● .login file, used when you log in● .emacs file, used when you launch


View Full Document

Duke CPS 108 - Dealing with errors

Download Dealing with errors
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 Dealing with errors 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 Dealing with errors 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?