What is the Use Of Static Fuction.

V

Vladimir S. Oka

Umesh said:
What is the use by making function Static.

Short answer: static functions are invisible to the other compilation
units. This means you're allowed to re-use the same function names in
other source files, and the linker won't balk at you.

I'm sure there's a more precise way of saying the above.

Cheers

Vladimir
 
J

James S. Singleton

Short answer: static functions are invisible to the other compilation
units. This means you're allowed to re-use the same function names in
other source files, and the linker won't balk at you.

I'm sure there's a more precise way of saying the above.

Maybe not more precise, but certainly simpler: A function F labeled
static can only be used by functions defined in the same file as F.
 
C

Chris Dollin

James said:
Maybe not more precise, but certainly simpler: A function F labeled
static can only be used by functions defined in the same file as F.

/referenced by name/, not /used/:

File A:

void user( void (*arg)(void) ) { arg(); }

File B:

#include <stdio.h>

extern void user( int (*arg)(void) );

static void used() { printf( ">> 'used' called\n" ); }

int main(void)
{
user( used );
return 0;
}

A uses `used` (it calls it). It cannot refer to it by name.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,174
Messages
2,570,940
Members
47,486
Latest member
websterztechnologies01

Latest Threads

Top