www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/07/29/17:02:24

To: djgpp AT sun DOT soe DOT clarkson DOT edu
From: "Nick van der Merwe" <NEEK AT cerecam DOT uct DOT ac DOT za>
Date: 29 Jul 93 17:54:10 SAST-2
Subject: Exception 14

Thanks to all who replied to my question. Sadly the problem is still
present.

The 2D dynamic allocation routines I am using are the written by Dr.
John M. Weiss (alloc2D.zip on omnigate I think). The arrays get
allocated fine , and everything works fine inside the code where it
was defined.

My *big* program has been split into smaller sub-programs which are
linked together. Previously the data was defined globally in file1
as eg. int data[512][512] ,with the next file that needed acces to
the data having a global definition "extern int data[512][512]" in
file2. This worked well , and the results in file2 were as expected.

Having a lot of data that is not needed later in the program , I
dynamically allocated the data using alloc2D.c . The problem arises as
soon as I try and acces the data in any file other than the one it
was created in(eg. file2).I now have a global definition of " int
**data" in file1 , which after allocated using Ialloc2D(nrow,ncol) ,
was easily manipulated with direct access to elements i.e. data[i][j]


In file2 I defined globally "extern int **data;". As soon as I try
and access an element of data , the program crashes. I tried to pass
directly the double pointer to file2 , which didn't crash , but gave
completely corrupted data for the array data.

I checked the contents of data just before leaving file1 , and
compared it with the contents of data as soon as I enter file2. The
data is completely different. I in fact wrote the results to files
using exactly the same routines , which gave 1 file correct(from
file1) @267150 bytes ? , and the next file(from file2) completely
corrupted @354942 bytes. I checked the value of the pointer at
creation of the array , just before leaving file1 and just after
entering file2. They all gave the same value.

So , the data is somehow being corrupted , as the pointer value was
correct. Nothing *should* happen to the data between function calls ,
but it does.

I would like to think that my mind has not just gone out to lunch ,
but I cannot see any reason why this should happen. I'm using
gcc1.09. Should I try 1.10?

Thank you


----------------------------------------------------------------------
Nick van der Merwe
Department of Surveying and Geodetic Engineering
University of Cape Town | " I have a cunning plan...."
South Africa            |       - Baldrick (Black Adder)
Internet: neek AT cerecam DOT uct DOT ac DOT za or nickvdm AT eleceng DOT uct DOT ac DOT za


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019