943,186 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 67783
  • C RSS
Jul 3rd, 2007
0

What is Static functions

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
narendharg is offline Offline
12 posts
since May 2007
Jul 3rd, 2007
1

Re: What is Static functions

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Sep 23rd, 2010
-2
Re: What is Static functions
Hey i am telling you the basic idea about the static functions.
Static functions are those functions which do not have the access to "this" pointer of the class and it can not be declared as virtual.
Main use of the static function is it can be called without crating object of the class.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mike2205 is offline Offline
4 posts
since Aug 2010
Sep 23rd, 2010
0
Re: What is Static functions
>Static functions are those functions which do not have the access to
>"this" pointer of the class and it can not be declared as virtual.

You need to learn the difference between C and C++ before resurrecting a three year old thread with completely incorrect and unhelpful information.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Dec 5th, 2011
0

Static function

Static function are used to avoid the access of the function from the other module.

By default normal functions can access by any module from the file; to avoid we can use static key word to the function.

Also if you have more than one; same functions name across file and if they were in static we will not get any errors.

-Thanks,
Girish.L.C
Reputation Points: 10
Solved Threads: 0
Newbie Poster
girishlc is offline Offline
1 posts
since Dec 2011
Message:
Previous Thread in C Forum Timeline: Expression Evaulation
Next Thread in C Forum Timeline: How to read integers from a string on integers of unknown length?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC