elliott.david 2009-02-17 18:26 采纳率: 25%
浏览 465
已采纳

什么是「静态」功能?

The question was about plain c functions, not c++ static methods, as clarified in comments.

Ok, I understand what a static variable is, but what is a static function?

And why is it that if I declare a function, let's say void print_matrix, in let's say a.c (WITHOUT a.h) and include "a.c" - I get "print_matrix@@....) already defined in a.obj", BUT if I declare it as static void print_matrix then it compiles?

UPDATE Just to clear things up - I know that including .c is bad, as many of you pointed out. I just do it to temporarily clear space in main.c until I have a better idea of how to group all those functions into proper .h and .c files. Just a temporary, quick solution.

转载于:https://stackoverflow.com/questions/558122/what-is-a-static-function

  • 写回答

11条回答 默认 最新

  • Lotus@ 2009-02-17 18:27
    关注

    static functions are functions that are only visible to other functions in the same file (more precisely the same translation unit).

    EDIT: For those who thought, that the author of the questions meant a 'class method': As the question is tagged C he means a plain old C function. For (C++/Java/...) class methods, static means that this method can be called on the class itself, no instance of that class necessary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!