delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/15/08:39:17

Date: Fri, 15 Jan 1999 14:32:17 +0100 (MET)
From: Wojciech Piechowski <voyt AT ds2 DOT pg DOT gda DOT pl>
To: djgpp AT delorie DOT com
Subject: Re: Problems with Arrays
In-Reply-To: <369E963C.ED7FB1DC@mailbox.uq.edu.au>
Message-ID: <Pine.GSO.3.96.990115142544.6397A-100000@delta.ds2.pg.gda.pl>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On Fri, 15 Jan 1999, Konstanty wrote:

> In a program of mine I have two arrays initilised with "new".
> 
> eg
> int *Map;
> Map=new int [225];
> 
> The problem is that when I write to one array it corrupts the other with
> the same data.
> 
> Is this because they were not initilised properly?
> If so how can you check if an array is initilised properly?

It seems that you tried to access the data behind the limit of the first
array:

A = new int[10];
B = new int[10];

A[15] = 1;   // this corrupts some data, possibly B's.
  ^^
You should also check if operator new didn't return NULL pointer.

--------------------\  Wojciech  Piechowski  /----------------------------
Student informatyki   \ voyt AT ds2 DOT pg DOT gda DOT pl /   Student of computer science
Politechnika Gdanska    \________________/  Technical University of Gdansk

- Raw text -


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