[LCP]global variable alternative

Mike & Penny Novack stepbystepfarm at shaysnet.com
Thu Apr 4 03:42:05 UTC 2002


Joachim,
    The question is sort of "philosophical" and related to ALL
programming languages (not specifically C).

    How much of a "purist" do you want to be? What's your philospophy
with regard to structured programming and functions being "pure
functions"?

    The "right" (ie: purist approach) this structure becomes an extra
parameter to all functions.

    The "practical" programmer is likely to reason thusly. Once the
structure has been initialized by the main process (or some
initialization process which reads the user database and fills in the
preferences) it never changes. In other words, it is from that point on
"constant" data used by all the other functions to determine their
behavior. Thus having those functions access it as a "global" makes
sense.

    Mike

PS -- There are OTHER consderations which can come into play. Right now
you are learning C and presumably all your links are "static" (ie: these
functions are all LINKED and so references can be resolved). If working
with a language where these might be DYNAMIC calls of functions (or
prcesses) compiled separately and NOT linked together you would have to
pass (the address of) the structure as an additional parameter.

PSS -- Anyone out there be able to explain to ME if/how C ever gets
involved with something like "dynamic calls"?






More information about the linuxCprogramming mailing list