what is a static function in C ?

S

sbmoon

Is there any difference between two functions defined below ?

static int my_func() ;

int my_func() ;

Thanks in advance!
 
J

Joona I Palaste

sbmoon said:
Is there any difference between two functions defined below ?
static int my_func() ;

int my_func() ;
Thanks in advance!

Your friendly C textbook should have already explained this.
A static function has a name visible in that translation unit only. A
normal function has a name visible across the entire program.
If you were to have two source files:
static int foo() {
return 0;
}
int bar() {
return 0;
}
(both files look the same)
you would get "function already defined" errors for bar, but foo would
compile absolutely OK.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"War! Huh! Good God, y'all! What is it good for? We asked Mayor Quimby."
- Kent Brockman
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top