Week4 Miscellaneous
Week4 Miscellaneous
CS-2303
System Programming Concepts
(Slides include materials from The C Programming Language, 2nd edition, by Kernighan and Ritchie and
from C: How to Program, 5th and 6th editions, by Deitel and Deitel)
• Inline functions
• Default Arguments
• Function Overloading
• Function Templates
• Example:–
inline int max(int a, int b) {
return (a>b) ? a : b;
}
• Reasons:–
• Reduce function call overhead—especially for small
functions in inner loops
• Takes advantage of compiler’s local optimizations
• Trade-off of inline functions
• Multiple copies of the function code are inserted in
the program (possibly making the program larger)
• The compiler may ignore the inline
qualifier
• Typically does so for all but the smallest functions
• Example
void prnt(int value, int base = 10);
…
prnt(100); //prints in base 10
prnt(100,16); //prints in base 16
prnt(100,8); //prints in base 8
prnt(100,3); //prints in base 3
CS-2303, C-Term 2010 Miscellaneous C++ Topi 8
cs
Default Arguments (continued)
square of integer 7 is 49
square of double 7.5 is 56.25
CS-2303, C-Term 2010 Miscellaneous C++ Topi 14
cs
Compiling Overloaded Functions
• May be overloaded