200 likes | 319 Vues
This guide explores the fundamentals of functions, libraries, and revision control systems in C programming. It details the structure of functions, including their argument passing methods, and introduces the concept of libraries for organizing related functions, such as the math library. You'll learn how to include libraries in your projects, the difference between static and dynamic libraries, and the importance of the LD_LIBRARY_PATH variable. Additionally, it covers the use of RCS for version control and the Make system for building programs efficiently.
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