Compatibility problem?

Alan Sparks als at roxanne.mlb.semi.harris.com
Wed Aug 8 03:52:35 AEST 1990


In article <1990Aug7.003432.1984 at rice.edu> onders at taac.ipl.rpi.edu (Timothy E. Onders) writes:

> [program omitted]
> When run on the Sun 3, attempting to write to the array gives a
>SEGV.  Attempting to read the array from dbx gives a "bad address" error.
>by examining the addresses of the three variables, there seems to be
>enough space for everything allocated. There is 4 megs of space between
>the array starting address, and the address of r.  Any ideas what might be
>causing this problem, and how I can get around it?

I haven't taken much time to research this really well... but I suspect
you've blown out the stack on the 68xxx CPU (especially with such a mondo
array).  I duplicated your situation, then devised a couple of
workarounds.

One workaround is to make the array "testm" static:

	static int testm[1024][1024];

This moves it off the stack, into the static data area.  Another
workaround (especially if you want to reclaim storage) is to dynamically
allocate the array.  One way to do it is:

	int **testm, i;

        testm = (int **) calloc(1024,sizeof(int *));
        for (i = 0;  i < 1024;  ++i)
          testm[i] = (int *) calloc(1024,sizeof(int));

The remainder of the code stays the same.  To reclaim storage afterward:

	for (i = 0;  i < 1024;  ++i)
          cfree(testm[i]);
        cfree(testm);

Some variant of these workarounds will solve your problem.  They work on a
local Sun 3/60 here.

Hope this helps.
-Alan



More information about the Comp.sys.sun mailing list