What is Static functions

Please support our C advertiser: Download Intel® Parallel Studio Eval
Reply

Join Date: May 2007
Posts: 12
Reputation: narendharg is an unknown quantity at this point 
Solved Threads: 0
narendharg narendharg is offline Offline
Newbie Poster

What is Static functions

 
0
  #1
Jul 3rd, 2007
Hi ,

I would thank you for replying for my thread,

I would like to know about static functions C language,what is the use of static functions.

Narendhar Gomathirajan
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 8,132
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 800
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: What is Static functions

 
0
  #2
Jul 3rd, 2007
A static function is a function with the static qualifier applied:
  1. static void foo ( void )
  2. {
  3. /* Blah blah */
  4. }
What it does is restrict visibility of the function to the translation unit in which it's declared. Functions are implicitly declared as extern by default, which means they're visible across translation units. You can compile the following, but it won't link:
  1. /* file1.c */
  2. void foo ( void )
  3. {
  4. }
  5.  
  6. extern void bar ( void )
  7. {
  8. }
  9.  
  10. static void baz ( void )
  11. {
  12. }
  1. /* file2.c */
  2. void foo ( void );
  3. void bar ( void );
  4. void baz ( void );
  5.  
  6. int main ( void )
  7. {
  8. foo(); /* OK: foo is extern by default */
  9. bar(); /* OK: bar is explicitly extern */
  10. baz(); /* Wrong: baz isn't visible in this translation unit */
  11. }
Last edited by Narue; Jul 3rd, 2007 at 4:28 pm.
In case you were wondering, yes, I do hate you.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 27328 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC