Download presentation
Presentation is loading. Please wait.
Published byShon Beasley Modified over 9 years ago
1
Chapter 12: Programming in the Large By: Suraya Alias 1-1
2
Figure 13.1 Preparing a Program for Execution 1-2
3
13.1 Using Abstraction to Manage Complexity Procedural Abstraction – Separation of what a function does from the details of how the function accomplished its purposes. – Example ; fopen(), sqrt() function Data Abstraction – Separation of the logical view of a data object (what is stored) from the physical view (how the information is stored) – Example ; data type double Information hiding – Protecting the implementation details of lower-level module from direct access by a higher-level module – Example ; only access data object through operators Encapsulate – Packaging as a unit a data objects and its operator 1-3
4
13.2 Personal Libraries : Header Files Header file – Has a.h extension, example header.h – Contains the interface information about a library needed by a compiler to translate a program system – Use the #include preprocessor directive 1-4
5
Figure 13.2 Header File planet.h for Personal Library with Data Type and Associated Functions 1-5
6
Figure 13.2 Header File planet.h for Personal Library with Data Type and Associated Functions 1-6
7
Figure 13.3 Portion of Program That Uses Functions from a Personal Library 1-7
8
13.2 Personal Libraries : Implementation Files Implementation file – File containing the C source code of a library function and other info – Example; if we create a personal library header.h we can include it in hello.c 1-8
9
Figure 13.4 Implementation File planet.c Containing Library with Planet Data Type and Operators 1-9
10
Figure 13.4 Implementation File planet.c Containing Library with Planet Data Type and Operators (cont’d) 1-10
11
13.4 Storage Classes 1.Auto – Default storage class of function parameters and local variables 2.Extern – Function names are of storage class extern – It will be available to the linker 3.Global variable – A variable that may be accessed by many functions in a program 4.Static – Storage class of variables allocated only once, prior to program execution 5.Register – Storage class of automatic variables that the programmer would like to have stored in register 1-11
12
Figure 13.5 Storage Classes auto and extern as Previously Seen 1-12
13
Figure 13.5 Storage Classes auto and extern as Previously Seen (cont’d) 1-13
14
Figure 13.6 Declaration of a Global Variable 1-14 In eg1.c, the declaration allocates space for global_var_x In eg2.c, the keyword extern allocates no memory. It only informs the compiler
15
Figure 13.7 Use of Variables of Storage Class extern 1-15
16
13.5 Modifying Functions for inclusion in a Library The exit() function allows premature termination of program execution The break function can be used to terminate a nested loop 1-16
17
Figure 13.9 Conditional Compilation of Tracing printf Calls 1-17
18
13.6 Conditional compilation Figure 13.10 Conditional Compilation of Tracing printf Calls 1-18
19
Figure 13.11 Header File That Protects Itself from Effects of Duplicate Inclusion 1-19
20
Figure 13.11 Header File That Protects Itself from Effects of Duplicate Inclusion (cont’d) 1-20
21
Figure 13.11 Header File That Protects Itself from Effects of Duplicate Inclusion (cont’d) 1-21
22
Figure 13.12 File Backup Using Arguments to Function main 1-22
23
13.7 Arguments to Function Main Command line arguments 1-23
24
13.7 Defining Macros with Parameters Macro – Facility for naming a commonly used statement or operation Macro expansion – Process of replacing a macro call by its meaning Use of parentheses Extending macro over two or more lines 1-24
25
Figure 13.13 Program Using a Macro with Formal Parameters 1-25
26
Figure 13.14 Macro Expansion of Second Macro Call of Program in Fig. 13.13 1-26
27
Figure 13.15 Macro Calls Showing Importance of Parentheses in Macro Body 1-27
28
Figure 13.15 Macro Calls Showing Importance of Parentheses in Macro Body (cont’d) 1-28
29
Figure 13.16 Macro Expansions of Macro Calls from Fig. 13.15 1-29
30
Chapter 13 – Dynamic data Structures 1-30
31
Pointers Dynamic data structures – A structure that can expand and contract as a program executes Nodes – Dynamically allocated structures that are linked together to form a composite structure 1-31
32
Pointers Pointers as function parameters – long_division(40, 3, ", &rem) Pointers representing arrays and strings – char *n or char n[] Pointers to structures – An array of structures was represented as a pointer to the first array element Refer table 14.1 1-32
33
1-33 Figure 14.1 Comparison of Pointer and Nonpointer Variables
34
1-34 Figure 14.2 Function with Pointers as Output Parameters
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.