NO

Author Topic: Silly question  (Read 3763 times)

Grincheux

  • Guest
Silly question
« 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.

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Re: Silly question
« Reply #1 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/
Code it... That's all...

Grincheux

  • Guest
Re: Silly question
« Reply #2 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.

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Silly question
« Reply #3 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

Offline fuhar_arora

  • Member
  • *
  • Posts: 1
Re: Silly question
« Reply #4 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.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Silly question
« Reply #5 on: July 01, 2022, 09:10:38 AM »
Visible only in current module / object file, (compilation unit).
May the source be with you