1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Declaring function as static

Discussion in 'C' started by answerme, Jan 22, 2008.

  1. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    If i declare a function as static what will happen
     
  2. technosavvy

    technosavvy New Member

    Joined:
    Jan 2, 2008
    Messages:
    52
    Likes Received:
    0
    Trophy Points:
    0
    for static functions in C++ go through:
    http://www.codersource.net/cpp_tutorial_static_functions.html


    and in C a static function has a name visible in that translation unit only. A
    normal function has a name visible across the entire program.

    If you were to have two source files with the undermentioned code:
    Code:
    static int fun() {
    return 0;
    }
    int morefun() {
    return 0;
    }
    you would get "function already defined" errors for function morefun( ), but fun( ) would compile successfully .


    a static function can only be called in the translation unit in which it is defined...
    hence a call to a static function from a file where it has not been defined will give a compilation error.

    friend why don't you try a bit of googling before u post a question..these kind of information is very very easily available on the net.
     

Share This Page