please dont rip this site

static functions

static functions are functions that are only visable to other functions in the same file. Consider the following code.





    * Function declarations (prototypes).

   /* Func1 is only visable to functions in this file. */   

   static void Func1(void);

   /* Func2 is visable to all functions. */

   void Func2(void); 

    * Function definitions
   void Func1(void)
     puts("Func1 called");
   void Func2(void)        
     puts("Func2 called");

If you attempted to compile this code with the following command,

   gcc main.c funcs.c   

it will fail with an error simular to.....

   undefined reference to `Func1'  

Because 'Func1' is declared as static and cannot be 'seen' by 'main.c'.


For some reason, static has different meanings in in different contexts.

  1. When specified on a function declaration, it makes the function local to the file.

  2. When specified with a variable inside a function, it allows the vairable to retain its value between calls to the function. See static variables.

It seems a little strange that the same keyword has such different meanings....

See also:

static variables

C++ extensions for static

Top Master Index Keywords Functions

Martin Leslie

file: /Techref/language/ccpp/cref/SYNTAX/static.htm, 3KB, , updated: 2003/3/20 10:58, local time: 2022/5/22 03:10,

 ©2022 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> static functions</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?


Welcome to!


Welcome to!