variable type

Guy Harris guy at auspex.UUCP
Wed Dec 21 03:59:18 AEST 1988


>Please give some hints regardingthe question: how can i decide to make
>a variable extern, static, etc...

Well, you think about it a bit, and then decide....

If you're talking about variables that aren't best made "auto", the best
rule is to make *everything* "static" except stuff that is actually
referred to by modules other than the one in which it's defined.  That
reduces the number of inter-module dependencies, and since you can
eliminate or change the meaning or behavior of "static" variables and
function without having to check any modules other than the one in which
they appear, it makes maintenance and change easier.

I think some UNIX C implementations may not be able to put "static"
variables into BSS space, however, so this may increase the size of the
executable image on those implementations.  Implementations using the
4.xBSD compiler and linker can put them in BSS space; I'm not sure about
ones using the System V compilers and linker, but I'd be surprised and
somewhat disappointed if they couldn't.  I don't know what other
implementations can or can't do; some of them may not have the notion of
BSS, so some huge array initialized, by default, to zero might take up
space no matter what storage class it has.



More information about the Comp.lang.c mailing list