Re: static functions

看板DFBSD_kernel作者時間21年前 (2005/04/01 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/5 (看更多)
On Thu, Mar 31, 2005 at 05:36:11PM +0200, Miguel Mendez wrote: > On Thu, 31 Mar 2005 16:11:17 +0100 > Jonathon McKitrick <jcm@FreeBSD-uk.eu.org> wrote: > > > > Sorry this is such a lame question, but I never quite figured out what > > 'static' does to a function declaration. Obviously for a variable, it > > allocates memory for the lifetime of the process rather than on the stack just > > for one function call. Only for function scope variables. > > But what about 'static' for all the kernel functions > > that have no return value? > > static foo(blah blah) restricts the scope of the function to that > module, i.e. it's not visible outside that .c file. You usually do that > to keep private functions from being called from somewhere else. That > way other parts of the program will only talk to the published API. That's right. It's also what happens with file scope variables. Beside keeping the namespace cleans, it allows the compiler to choose a different ABI for internal functions. It also allows the compiler to warn about unused local functions and variables. Joerg
文章代碼(AID): #12J3iI00 (DFBSD_kernel)
文章代碼(AID): #12J3iI00 (DFBSD_kernel)