[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Why static function?

Posted on 2010-01-06
Medium Priority
Last Modified: 2012-05-08
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.
Question by:naseeam
  • 3
  • 2
LVL 32

Assisted Solution

by:Daniel Wilson
Daniel Wilson earned 320 total points
ID: 26195591
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.

Author Comment

ID: 26195649
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.,
LVL 53

Accepted Solution

Infinity08 earned 1680 total points
ID: 26195657
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).
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 26195748
What is a compliation unit?  Is it a file?
LVL 53

Expert Comment

ID: 26195765
>> 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 ...)

Author Closing Comment

ID: 31673775
Great Super fast answers.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question