what is a static function in C ?

Discussion in 'C Programming' started by sbmoon, Sep 30, 2003.

  1. sbmoon

    sbmoon Guest

    Is there any difference between two functions defined below ?

    static int my_func() ;

    int my_func() ;

    Thanks in advance!
     
    sbmoon, Sep 30, 2003
    #1
    1. Advertisements

  2. Your friendly C textbook should have already explained this.
    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:
    static int foo() {
    return 0;
    }
    int bar() {
    return 0;
    }
    (both files look the same)
    you would get "function already defined" errors for bar, but foo would
    compile absolutely OK.

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "War! Huh! Good God, y'all! What is it good for? We asked Mayor Quimby."
    - Kent Brockman
     
    Joona I Palaste, Sep 30, 2003
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...