• C

Why static function?

What is purpose of a staic function?  Exactly how does static function differ with regular function?  In what situation(s) static function should be defined?

We write C, C++, Assembly for Freescale ColdFire Microcontroller MCF5485.
LVL 1
naseeamAsked:
Who is Participating?
 
Infinity08Commented:
What DanielWilson said, was about static member functions.

A regular static (non-member) function is a function that has internal linkage - ie. it is only visible in the same compilation unit where it is defined. It cannot be called from another compilation unit (as opposed to functions with external linkage).
0
 
Daniel WilsonCommented:
In an object-oriented language, a static function may be called without instantiating the class that defines it.

This permits it to be called with lower overhead than a non-static method of the class.  Of course, it also means that it has no access to instance data.
0
 
naseeamAuthor Commented:
Thank you for a great answer but I should have done better job of asking the question.

I meant why static functions in a .c file.  There are some static functions defined in a .c file.  Why would you define them static?  These static functions are not defined in a class, that's C++.  I am talking about 'C' Language static functions.,
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
naseeamAuthor Commented:
What is a compliation unit?  Is it a file?
0
 
Infinity08Commented:
>> What is a compliation unit?  Is it a file?

It roughly corresponds to a .c file (with all the headers included in it, directly or indirectly).
It is the code that a compiler compiles into an object file. Each compilation unit results in an object file. The linker then links all these object files into the final binary (executable, or library, or ...)
0
 
naseeamAuthor Commented:
Great Super fast answers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.