IonicWind Software

IWBasic => General Questions => Topic started by: pistol350 on November 11, 2008, 01:35:41 AM

Title: POINTERS (our friends...) :)
Post by: pistol350 on November 11, 2008, 01:35:41 AM
I have a few questions about pointers.
First, is it correct to do this :

Pointer pMypointer[10] 'Just an array of pointer

If so, can i initialize this pointer like this ? :

pMypointer=NULL  ' I think this does not work as I would expect it to.  ???

So would this do the job ?
If so, is it the proper way to do that ?

For temp=0 to 9
pMypointer[temp]=NULL
next temp



Thanks.
Title: Re: POINTERS (our friends...) :)
Post by: Rock Ridge Farm (Larry) on November 11, 2008, 05:46:03 AM

If I remember correctly (and that is a bit of a reach)

Pointer mypointer[10] declares an array of 10 pointers - an address in the initialized stack area is assigned to the pointer.

mypointer=Null; sets the address of the array of pointers to null - not very useful.

The following sets the contents of each element of mypointer to Null.

For temp=0 to 9
   pMypointer[temp]=NULL
next temp
Title: Re: POINTERS (our friends...) :)
Post by: pistol350 on November 12, 2008, 05:38:56 AM
Hi Larry!

Quotemypointer=Null; sets the address of the array of pointers to null - not very useful.
Not very useful indeed as it only initializes the first pointer of the array.

I asked the question because i noticed that pointers are not always initialized after their creation.
So in case i defined an array of pointers just like the example above,
i thought that i should initialize all of them to prevent unexpected results.

Thanks again.
Title: Re: POINTERS (our friends...) :)
Post by: Rock Ridge Farm (Larry) on November 12, 2008, 06:20:54 AM
I think that is correct - when a pointer is created it inherits the trash that just happens to
be at the assigned memory location - that is why you should always initialize pointers.
I initialize all vars just to be safe.
You can get some strange results if you do not.