200 likes | 317 Views
Functions. Functions. The basis for everything int main() is a function Both a “procedure” and a “function”. Format of a function. type name (type arg1, type arg2,...) { type localvar; ... }. By Value/By Reference. The arguments to functions are by value
E N D
Functions • The basis for everything • int main() is a function • Both a “procedure” and a “function”
Format of a function • type name (type arg1, type arg2,...) {type localvar; ...}
By Value/By Reference • The arguments to functions are by value • If you want to change a variable, must use a pointer.
Libraries • A bunch of functions that go together • The “math” library
Using libraries • Use “#include” • Use -Ldir to include libraries from other directories • Use -llibname to include them in the compile • Name of lib: m -> libm.a
Shared libraries • There are also libm.so which are dynamic libraries • Usually found in /usr/lib, /lib, or /usr/local/lib • LD_LIBRARY_PATH environment variable
Creating your own library • The “ar” command • The “ranlib” command
RCS: Save yourself pain • Useful for when working in a group • Allow you to “check” programs in and out • Leave messages to help tell what happend
The commands • ci -u file (Check it in) • co -l file (Check it out) • rcsdiff file (Find differences) • rlog file (look at change log)
Make • The central way to “make” programs • Uses a “recipe” for compiling programs • Takes a bit to learn but very useful
C Preprocessor commands • #include • #define • #if .... #endif • #ifndef