[comp.sys.mac.programmer] C global scoping rules

pollock@usfvax2.EDU (Wayne Pollock) (06/18/88)

In article <55576@sun.uucp> landman@sun.UUCP (Howard A. Landman) writes:
>In article <10896@apple.Apple.Com> dan@apple.UUCP (Dan Allen) writes:
>> It is very rare for an application to REALLY NEED more than 32K of global
>> data.  I submit that if an app is using more than 32K, then it is written
>> wrong, that is, the allocation of the space should be at a more local scope
>> or whatever.
>
> ...
>
>I have a program which uses two large global arrays, with sizes about 1500K
>each.  (This is, of course, not a Mac program.)  These are accessed from ALL
>OVER the program.  How are you suggesting this should be done on a Mac?
>
>Studies have shown that over 90% of Pascal variables are either completely
>local (to one procedure) or completely global; very few are local to a
>group of procedures.  In C, it's 100%, because you don't have lexical
>scoping.  Therefore, in C,  ANY DATA WHICH MUST BE ACCESSED BY TWO OR MORE
>PROCEDURES MUST BE GLOBAL, or at least accessible through global pointers,
>unless it is explicitly passed as arguments.  ...

Well, not quite.  In C, data may be declared static outside the scope of any
function.  Such data is accessable to any functions defined in the same
file as the data, but not to other functions in other files.

If you need to get around the limit, there are sevaral ways.  One is
to use resources to store the arrays and load them into memory
dynamically at program startup.

A second way would be to create a function to access the arrays, and have
the arrays declared local to that function.  This will, of course, give a
performance penalty for each access; in some application this isn't a
serious drawback since the speed of the program is limited by other
factors anyway.

I agree that the 32k limit is silly and should be abolished.  What Dan Allen
fails to understand is that sometimes poorly written programs must be ported
and used, and that it may not be feasible to redesign the program to use
less global data.

Wayne Pollock (The MAD Scientist)	pollock@usfvax2.usf.edu
Usenet:		...!{ihnp4, cbatt}!codas!usfvax2!pollock
GEnie:		W.POLLOCK