Pelles C forum

C language => Beginner questions => Topic started by: Grincheux on December 15, 2021, 07:38:54 pm

Title: Silly question
Post by: Grincheux on December 15, 2021, 07:38:54 pm
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.
Title: Re: Silly question
Post by: Vortex on December 15, 2021, 08:28:30 pm
Hi Grincheux,

Quote
Unlike 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/
Title: Re: Silly question
Post by: Grincheux on December 15, 2021, 08:32:06 pm
Thank You Vortex.


Quote
Another reason for making functions static can be reuse of the same function name in other files.
Can be dangerous. I did not know.
Title: Re: Silly question
Post by: John Z on December 16, 2021, 11:21:29 am
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
Title: Re: Silly question
Post by: fuhar_arora on July 01, 2022, 08:37:37 am
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.
Title: Re: Silly question
Post by: TimoVJL on July 01, 2022, 09:10:38 am
Visible only in current module / object file, (compilation unit).