[comp.sys.amiga.programmer] Arrays in C

vac253v@monu6.cc.monash.edu.au (Richard Jones) (02/07/91)

Hi there all you C masochists.

I am slowly changing my programming to 68k, but here's one final little
doosy to get you all thinking. I am using Aztec 3.6a and the arrays I am
setting up are doing really wierd things. Basically, I have this array
callled map[200][200], guess what it holds.... (altitudes, if you hadn't 
guessed). Now, main() is at the end of the program (a hangup from old
Pascal programming days). The first thing that this incredibly complex 
main() does is the following.....
		map[0][0] = -20;
		map[0][100] = -20;
		map[100][0] = 0;
		map[100][100] = 0;

Now, I compile the thing with the -n and -g options to debug it with SDB.
BTW, it doesn't work without these options. Using SDB, I find that the
third assignment above ends up placing -20 into 100,0 and 100,100 is random.

The unassebled code for these two lines (unavailable) looks real wierd.
something like a move.l  -169,(a0)-
				 move.l  -201,(a1)+

Any help would be appreciated, thanx.


Richard Jones                  | *DISCLAIMER*  -  All opinions contained 
vac253v@monu6.cc.monash.edu.au | within are mine, MINE,  ALL MIIIIINE!!!!!! 

mcmahan@netcom.COM (Dave Mc Mahan) (02/10/91)

 In a previous article, vac253v@monu6.cc.monash.edu.au (Richard Jones) writes:
>Hi there all you C masochists.
>
>I am slowly changing my programming to 68k, but here's one final little
>doosy to get you all thinking. I am using Aztec 3.6a and the arrays I am
>setting up are doing really wierd things. Basically, I have this array
>callled map[200][200]

>The first thing that this incredibly complex 
>main() does is the following.....
>		map[0][0] = -20;
>		map[0][100] = -20;
>		map[100][0] = 0;
>		map[100][100] = 0;
>
>Now, I compile the thing with the -n and -g options to debug it with SDB.
>BTW, it doesn't work without these options. Using SDB, I find that the
>third assignment above ends up placing -20 into 100,0 and 100,100 is random.
>
>The unassebled code for these two lines (unavailable) looks real wierd.
>something like :
>     move.l  -169,(a0)-
>     move.l  -201,(a1)+

Well, you have some problems (I think) due to your using such a HUGE array
declaration.  If your array is 200x200, that means you have 40,000 elements
in it.  If you are using 4 byte integers for this, your asking the amiga to
declare 160,000 bytes of space for your arrays.  This is a bit larger than
the model your compiler can handle easily.  What you should do is either
use the AllocMem() call and then use pointers into the returned memory space,
or use the +D option to ensure that you are able to go past the limits of
the compiler.  You might also have to use the +C option, but I doubt it.  You
really should use the AllocMem() system call (or malloc() or alloc() if you
want to be portable) to aquire this much memory.  You can't allocate this much
on your stack, so that means you can't have map[][] declared within a function,
but instead must declare it as a global data structure.  If you still have
problems after using the +D option and moving the map[][] declaration outside
of any functions, let me know and I'll see what I can find.



>Richard Jones                  
>vac253v@monu6.cc.monash.edu.au


   -dave

-- 
Dave McMahan                            mcmahan@netcom.com
					{apple,amdahl,claris}!netcom!mcmahan