Item

ArrayNew

Initialize an existing ITEM as an array

Syntax

Signature
int ArrayNew( ITEM *destination, int64_t length );

Arguments

destination is the ITEM to replace.

length is the number of slots to create.

Return value

1 when the array was created, or 0 for a NULL destination or negative length.

Description

Releases the previous contents of the destination. The new slots start as NIL. A length of zero creates an empty array.

Example

arraynew.c
#include "xdev-wtui.h"

#include <stdio.h>

int main( void )
{
   ITEM *array = ItemNew( NULL );

   if( !ArrayNew( array, 2 ) )
   {
      ItemRelease( array );
      return 1;
   }
   ArraySetNI( array, 1, 42 );
   printf( "%d\n", ArrayGetNI( array, 1 ) );
   ItemRelease( array );

   return 0;
}

Output

42

See also