1 / 20

Functions

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

otylia
Download Presentation

Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Functions

  2. Functions • The basis for everything • int main() is a function • Both a “procedure” and a “function”

  3. Format of a function • type name (type arg1, type arg2,...) {type localvar; ...}

  4. By Value/By Reference • The arguments to functions are by value • If you want to change a variable, must use a pointer.

  5. Example Function

  6. Libraries

  7. Libraries • A bunch of functions that go together • The “math” library

  8. 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

  9. 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

  10. Creating your own library • The “ar” command • The “ranlib” command

  11. Revision Control System (rcs)

  12. 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

  13. The commands • ci -u file (Check it in) • co -l file (Check it out) • rcsdiff file (Find differences) • rlog file (look at change log)

  14. Make

  15. Make • The central way to “make” programs • Uses a “recipe” for compiling programs • Takes a bit to learn but very useful

  16. Example Makefile

  17. Modular programming

  18. C Preprocessor

  19. C Preprocessor commands • #include • #define • #if .... #endif • #ifndef

  20. End of Show

More Related