'static' function?

Jeremy Harris jgh at mifnet.gec-mi-ate.co.uk
Thu Jul 3 21:10:29 AEST 1986


In article <131 at kaist.UUCP> jhhur at kaist.UUCP (Jin H. Hur) writes:
>What is the meaning of 'static' function?  Does it mean that the return value
>is allocated a memory location rather than the top of C stack?  If so, what is
>the relevance of a memory location for a return value?

No, it restricts the visibility of the function (scope) to the current file
(module). This means 1) other modules can't use it as an entry point, 2) the
name of the function may be reused in other modules of the same program,
3) the symbol table is smaller, less cluttered, etc (if you tell the compiler
and/or loader to delete local-only symbols).

Btw, lots of compilers return values from functions in register(s) rather
than on the stack, for speed. One compiler I've seen (for a 68K) has a switch
to return pointer values in A0  *as well as*  D0.  Interesting, no?

Now, to light lotsa flames,	:-)
I think C's usage of 'static', as applied to functions, to mean 'don't export'
is unfortunate.  It is non-intuitive, as exemplified by the query above,
and encourages the bad coding practice of exporting everything (since the
default is to export).
I would prefer the use of 'export' and 'import' as in Modula, with 'import'
replacing 'extern'.
The same arguments apply to variables as functions.
This will break quite a lot of existing code, so must be availible as a
compiler switch, to be used on all new code.  Later, it will become the
compiler defaualt, with a switch to turn it off.
Ok, it's going to mean more typing during initial coding.  But how much
debugging time will it save you?   *Anything* which encourages modular
programming has got to be a good idea.

How about it?

Jeremy Harris					...!mcvax!ukc!hrc63!miduet!jgh
(I don't speak for my employer)			jgh at gec-mi-at.co.uk



More information about the Comp.lang.c mailing list