From: | Jack York |
Date: | 14 Aug 2000 at 15:13:40 |
Subject: | Re: Passing a ptr |
Hello Niels
On 13-Aug-00, Niels de Koning wrote:
>> It works fine as is but I when I place it in a function and call that
>> function, it doesn't work at all. I know it is how I am declaring
>> the args but I can't figure it out. Given a funtion name of
>> Makearray I tried MakeArray (mystruct **array) but it didn't
>> like that at all. Can someone show me the correct way of passing
>> the variable array?
>
> If you want to return a value from a function in the parameter list you
> always have to add a level of indirection to that parameter, which means
> there would have to be another pointer-level added in this case.
>
> MakeArray (mystruct ***array);
>
> void main()
> {
> Array **array;
> MakeArray( &Array );
> }
Ok, I tried the following but it doesn't work. I am assuming I am
not addressing the variables in the correct way within the funtion.
Here's what I am doing:
BOOL MakeArray (mystruct ***array, LONG arraysize)
{
if (*array = (mystruct **) AllocVec ( arraysize * sizeof (mystruct)))
{
for (i = 0; i < arraysize; i++)
{
if ( ! *((array[i]) = (mystruct) AllocVec (sizeof (mystruct)))
break;
Jack