[futurebasic] Re: [FB] C array garbage value

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2017 : Group Archive : Group : All Groups

From: Ken Shmidheiser <kshmidheiser@...>
Date: Fri, 10 Feb 2017 23:22:15 -0500
Looks like the array must be properly initialized before being populated.

Try this.

Ken


include "NSLog.incl"

BeginCFunction
long MyFunction1( long count )
{
   long *dim = malloc(count*sizeof(long));
   dim[count];
   for ( long d = 0; d < count; d++ )
   {
       dim[d] = 15;
   }
   long d = dim[1];   // garbage value -- gone I hope
   NSLog(@"%lu",d);

return d;
}
EndC
toolbox fn MyFunction1( long ) = long

print fn MyFunction1( 10 )

RunApplicationEventLoop()