File: array_alloc.h

package info (click to toggle)
libgdchart-gd2 0.11.5-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 276 kB
  • ctags: 296
  • sloc: ansic: 3,342; makefile: 229
file content (41 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* GDCHART 0.11.2dev  ARRAY_ALLOC.H  Mar 2002 */
/* Copyright Bruce Verderaime 2002-2004 */
/* Contributed in part or whole by Don Fasen and Darren Kent */

#ifndef _ARRAY_ALLOC_H
#define _ARRAY_ALLOC_H

/* ----- no dynamic auto array, need to mallocate space ----- */
#if !defined (__GNUC__)  || defined (__STRICT_ANSI__)

#include <stdlib.h>

float	**allocate_array_float( int nrs, int ncs );
char	**allocate_array_char( int nrs, int ncs );
int		**allocate_array_int( int nrs, int ncs );

#define CREATE_ARRAY1( arr, type, nels )		type *arr = (type*)malloc( (nels) * sizeof(type) )
												/* array2 can't do ptr (*) types */
#define CREATE_ARRAY2( arr, type, nrs, ncs )	type **arr = allocate_array_##type( nrs, ncs )

#define FREE_ARRAY1( arr )						if( arr ) { free( (void*)arr ); arr = NULL; } else
#define FREE_ARRAY2( arr )						if( arr )						\
													{							\
													if( arr[0] )				\
														free( (void*)arr[0] );	\
													free( (void*)arr );			\
													arr = NULL;					\
													}							\
												else

/* ----- avoid alloc, let the stack do the work ----- */
#else

#define CREATE_ARRAY1( arr, type, nels )		type arr[ nels ]
#define CREATE_ARRAY2( arr, type, nrs, ncs )	type arr[ nrs ][ ncs ]
#define FREE_ARRAY1( arr )
#define FREE_ARRAY2( arr )

#endif

#endif /*_ARRAY_ALLOC_H */