News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Silly question

Started by Grincheux, December 15, 2021, 07:38:54 PM

Previous topic - Next topic

Grincheux

I use the verb "static" for a function to find unreferenced function.
What is the interest of the word 'static'?
I thing I did not undersood.
If it is to tell the compiler to not move the function, the interest is poor.

Vortex

Hi Grincheux,

QuoteUnlike global functions in C, access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making functions static can be reuse of the same function name in other files.

https://www.geeksforgeeks.org/what-are-static-functions-in-c/
Code it... That's all...

Grincheux

Thank You Vortex.


QuoteAnother reason for making functions static can be reuse of the same function name in other files.
Can be dangerous. I did not know.

John Z

Quote from: Grincheux on December 15, 2021, 07:38:54 PM
I use the verb "static" for a function to find unreferenced function.

Hmmmm - might be another job for Line Counts+
It know the functions, and knows what functions are called within each function.  So could add a counter to see if each function is ever called by another.  Of course there is always one never called by another too . . . .

You also could use Named BookMarks as well in place of static.  Would be faster than searching for "static" which might just be a normal 'static' variable too.

John Z

fuhar_arora

The static keyword is used before the function's name to make any function as the static function. And the scope of the static function in C is limited to its object files or only a program. It means that the static function is only visible to its program files and restricts other files or programs from accessing the static function.

TimoVJL

Visible only in current module / object file, (compilation unit).
May the source be with you