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