954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What is Static functions

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

narendharg
Newbie Poster
12 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

A static function is a function with the static qualifier applied:

static void foo ( void )
{
  /* Blah blah */
}

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:

/* file1.c */
void foo ( void )
{
}

extern void bar ( void )
{
}

static void baz ( void )
{
}
/* file2.c */
void foo ( void );
void bar ( void );
void baz ( void );

int main ( void )
{
  foo(); /* OK: foo is extern by default */
  bar(); /* OK: bar is explicitly extern */
  baz(); /* Wrong: baz isn't visible in this translation unit */
}
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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.

mike2205
Newbie Poster
4 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

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

girishlc
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You