[comp.sys.mac.programmer] C-Compilers

frizby@geowhiz.UUCP (Jim Grandt) (03/08/88)

MacProgrammers:

        I recently purchased  a  MAC  ][  (which  I  haven't
received  yet)  and would like to order a compiler.  I would
like one that doesn't restrict arrays and supports the 68881
FPP.

        I have looked at the 3 listed  above  and  only  one
allows  arrays of 32K or bigger w/o a fix.  My needs require
large arrays, math processing, and graphics.

	THANX IN ADVANCE...ANY SUGGESTIONS APPRECIATED.

James "frizby" Grandt
Electrical Engineer
Department of Geology & Geophysics UW - Madison
1215 West Dayton Street Madison, WI  53706

BELL: 	(608) 262-9698 
ARPA:   geowhiz!frizby@spool.wisc.edu
UUCP:  {seismo, topaz, harvard, ihnp4}!uwvax!geowhiz!frizby
BITNET: frizby%geowhiz.uucp%spool.cs.wisc.edu@wiscvm.bitnet

dowdy@Apple.COM (Tom Dowdy) (03/09/88)

In article <669@geowhiz.UUCP> frizby@geowhiz.UUCP (Jim Grandt) writes:
>MacProgrammers:
>
>        I have looked at the 3 listed  above  and  only  one
>allows  arrays of 32K or bigger w/o a fix.  My needs require
>large arrays, math processing, and graphics.

I don't think that any of the above listed compilers allow greater than
32K data segments by default.
(although MPW DOES if you tell it you wish larger segements at link)
Still, this isn't really needed, which is why I am posting this:

There seems to be this train of thought that one is unable to use arrays
greater than 32K without all kinds of modifications to the original code.
(A perfect example of this is a unix ray tracer that declared a 2 Meg
array for pixel storage)

If in C, I declare
typedef struct MyDataElement
	{
	char aChar
	int aInt
	short aShort
	} MyDataElement;

and then a pointer
MyDataElement*	myArrayPointer;

And allocate enough space for myArrayPointer via a NewPtr call,
I can then refer to myArrayPointer[0], myArrayPointer[1] etc up to
the amount of space I have declared.

Viola!  A greater than 32K array, declared differently, but accessed
exactly the same as one declared as MyDataElement myArrayPointer[1000000].

This is really no different than using char* and a malloc() call instead
of declaring your strings as string[1000].  And of course, one can
also use this method for non-structured arrays, such as float* floatArray;

And really, this is a better way to do things as you can allocate as much
space as you need based on what you are going to load into the array.
You can also later grow the array with SetPtrSize, (or for that matter,
shrink it).  A word of warning, however, you are asking for LARGE
non-relocatable blocks, so one needs to take care to avoid heap fragmenting.
(And SetPtrSize in particular can be very slow should it need to actually
move the block)  But I think all will agree that it is better to determine
memory needs at runtime rather than at compile time.

If I am doing something hopelessly wrong, I'm sure someone will point it out,
but I am pretty sure this is all legal.  Either that, or I've been incredibly
lucky for a very long time.
  
  Tom Dowdy                 CSNET:    dowdy@apple.CSNET
  Apple Computer MS:27Y     AppleLink:DOWDY1
  20525 Mariani Ave         UUCP:     {sun,voder,amdahl,decwrl}!apple!dowdy
  Cupertino, CA 95014    
  "The 'Oo-Ah' Bird is so called because it lays square eggs."