Presentation is loading. Please wait.

Presentation is loading. Please wait.

CISC105 – General Computer Science

Similar presentations


Presentation on theme: "CISC105 – General Computer Science"— Presentation transcript:

1 CISC105 – General Computer Science
Class 18 – 08/02/2006

2 #1 Reason to use Libraries
Code REUSE! If the code is specific to solving a specific problem chances are you will not need libraries

3 Functions in Personal Libraries
When developing a personal library you should make the functions as general as possible. Look to variables to see if they are needed or if they should be included as input variables.

4 Functions in Personal Libraries
Limitations of the functions should be known and tested for so a program can terminate gracefully Graceful termination is always preferable to corrupt data! Use of the exit() function in a library can be used to gracefully exit a program See my_math.h, my_math.c and my_math_test.c

5 The exit command exit will terminate the run of a program and as such should be used with caution! Avoid using exit(0) as this will indicate a normal termination of the program. Only use exit(1) when error recovery is not possible or useful

6 Review When is it a good idea to request a storage class of register? static? const? What are the two types of files that we need to define a library? Why do we need to #include the header file of a library in the libraries implementation file?

7 Conditional Compilation
The C preprocessor recognizes commands that allow the user to select parts of a program to be compiled or omitted. We can add debugging printf statements in a program and can choose to compile using the statements or to omit them See my_math_test2.c

8 Conditional Compilation
We can also use Conditional Compilation to define what library to use to avoid duplicate declarations Conditional Compilation statements can be used for OS specific statements in code (#define WINDOWS or #define UNIX) #if defined (WINDOWS) statements #elif defined (UNIX) statements #else statements #endif

9 More command line arguments
What are the 2 variables that we need to include in our main declaration in order to accept command line arguments? What does int argc tell us? What does char *argv[] tell us? See command_line1.c

10 Macros A macro is a facility for naming a commonly used statement or operation. We define a macro by using the #define preprocessor command Macros can take parameters macro expansion is the process of replacing a macro call by its meaning See macro1.c

11 Macros Is macro just another name for a function?
Macros differ from functions in that they do not require allocation and deallocation Macro code is evaluated during preprocessing and the code is expanded Watch out for ()!!! Improper placement of parentheses can lead to improper execution See macro2.c

12 Questions Questions about anything we have gone over today?
Questions about anything related to Programming in C? Questions about the Lab/Project?


Download ppt "CISC105 – General Computer Science"

Similar presentations


Ads by Google