storage class static of functions

Discussion in 'C Programming' started by asit, Jan 15, 2008.

  1. asit

    asit Guest

    Can functions have static storage clas ?? If yes, what is it's
    advantage ??
    asit, Jan 15, 2008
    #1
    1. Advertising

  2. asit

    Guest

    Chris Dollin wrote:
    > Willem wrote:
    >
    > > asit wrote:
    > > ) Can functions have static storage clas ?? If yes, what is it's
    > > ) advantage ??
    > >
    > > No, functions can not have static storage class.

    >
    > That's an interesting claim; to be clear, are you saying that
    >
    > static void nuffin(void) {}
    >
    > isn't legal, or are you saying that the notion of "storage class"
    > appropriate to variables isn't applicable to functions?


    The latter. It's actually referred to as "storage duration" rather
    than "storage class" in the standard. The result of applying the
    'static' keyword to the definition of a variable is to give that
    variable static storage duration. The result of applying the 'static'
    keyword to the definition of a function is to give that function's
    name internal linkage.
    , Jan 16, 2008
    #2
    1. Advertising

  3. "asit" <> wrote in message
    news:...
    > Can functions have static storage clas ??

    yes , they can.
    If yes, what is it's advantage ??
    the "advantages" , if one can call that , are:

    the static keyword makes the functions local to the file (more accurately
    "translation unit") in which it is defined. This means the function can be
    called only within that fileTherefore it
    1) Provides modularity by data hiding and
    2) Gives an opportunity to the compiler to optimize better (by say inlining)

    In certain cases a "static" "inline" function is a type-safe replacement for
    a preprocessor macro.
    Ravishankar S, Jan 16, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Hoffmann
    Replies:
    3
    Views:
    2,812
    Christian Jan├čen
    Aug 8, 2003
  2. sarathy
    Replies:
    2
    Views:
    649
    sarathy
    Jul 17, 2006
  3. Replies:
    5
    Views:
    392
  4. jacob navia

    Re: storage class static of functions

    jacob navia, Jan 15, 2008, in forum: C Programming
    Replies:
    2
    Views:
    266
    Chris Dollin
    Jan 15, 2008
  5. Willem

    Re: storage class static of functions

    Willem, Jan 15, 2008, in forum: C Programming
    Replies:
    2
    Views:
    274
    Chris Dollin
    Jan 15, 2008
Loading...

Share This Page