IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Parker on March 21, 2007, 04:04:11 PM

Title: Pointer to array of pointers
Post by: Parker on March 21, 2007, 04:04:11 PM
This topic is confusing me. I had some spare time and thought I'd make an ArrayList class (I need this for aeon's browser too), but I have a problem:

An ArrayList stores a pointer to an array of pointers. I know that in C I can call this void **array; but I'm having a little trouble making it work in Aurora. I know that Aurora only supports one level of indirection though it is possible to use more, but this is what is giving me trouble.

I have a pointer (void*) called "array" inside of the class. In the constructor, it is initialized to be an array of pointers (array = new(pointer, 10);). The problem I'm having is accessing it. There are many different syntaxes that compile but generate errors at runtime. Here are what I've tried:

I've run out of ideas. Please, how should I properly access the elements of the array?
Title: Re: Pointer to array of pointers
Post by: Ionic Wind Support Team on March 21, 2007, 04:25:21 PM
Perhaps this will help you alng the way:


pointer *pa;
global sub main()
{
pa = new(int,100);
*pa[0] = AllocHeap(255);
*pa[1] = AllocHeap(255);
*(string)(*(pointer)pa[0]) = "This is a dynamically created string array";
*(string)(*(pointer)pa[1]) = "hello";
print(*(string)(*(pointer)pa[0]));
print(*(string)(*(pointer)pa[1]));

delete *pa[0] ;
delete *pa[1] ;
delete pa;
while (GetKey() = "") ;

}


NEW doesn't care about the type, although it does return that type to an unitialized pointer which can cause confusions.  The easiest way to handle it is to just use INT instead of POINTER in your NEW statement.  Which allocates the memory to the correct size.

Paul.
Title: Re: Pointer to array of pointers
Post by: Parker on March 22, 2007, 09:56:19 PM
It turns out I was thinking too complicated. After looking at your example, I figured out all I needed to do was use pointer* as the type and *array[ i ] = ...

Thanks.