Thread: Static Function Understanding

  1. #1
    Registered User
    Join Date
    Jan 2013
    Location
    UK
    Posts
    19

    Static Function Understanding

    I think I have the understanding correct, but just encase could someone confirm this for me.

    In C, a static function is used to state that only the app/dll which contains the code for the function can use the function. So if I create a DLL only calls from inside the DLL can access the static function, and not the application using the DLL.

    Best way I can think of helping explain, if the above doesn't make any sense.

    DLL(contains static function)

    APP using DLL can use all functions except for the static one(s).

    -----------------------

    I would just like to note, I'm slightly confused because by what I've read a static function in c++ is different to that of a static function in c. I just want to make sure I have the correct meaning for c.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    It seems you've got it right.

    A "static" function is only visible in the file where it is defined. See FAQ > static and extern? - Cprogramming.com for an example.

    Bye, Andreas

  3. #3
    Registered User
    Join Date
    Jan 2013
    Location
    UK
    Posts
    19
    Thank you for your reply. You just answered my next question about extern with functions as well

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    If you want to think in object-oriented terms, you could think of one object file as one class. The static functions in the object file can be regarded as private methods of that class.

  5. #5
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Functions that are declared with “static” before them are said to have internal linkage. When that keyword is omitted, they have external linkage and may be called by other translation units.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding function
    By peste19 in forum C Programming
    Replies: 6
    Last Post: 05-14-2012, 04:09 AM
  2. Help understanding this function...
    By Siaw Ys in forum C Programming
    Replies: 1
    Last Post: 12-02-2011, 02:03 PM
  3. Replies: 8
    Last Post: 01-19-2009, 07:42 PM
  4. Replies: 6
    Last Post: 12-13-2007, 08:20 PM
  5. need help understanding this function
    By Lince in forum C Programming
    Replies: 4
    Last Post: 08-04-2007, 10:29 AM