File: onstack.h

package info (click to toggle)
paraview 4.0.1-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 526,572 kB
  • sloc: cpp: 2,284,430; ansic: 816,374; python: 239,936; xml: 70,162; tcl: 48,295; fortran: 39,116; yacc: 5,466; java: 3,518; perl: 3,107; lex: 1,620; sh: 1,555; makefile: 932; asm: 471; pascal: 228
file content (72 lines) | stat: -rw-r--r-- 1,777 bytes parent folder | download | duplicates (14)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 *	Copyright 1997, University Corporation for Atmospheric Research
 *	See netcdf/COPYRIGHT file for copying and redistribution conditions.
 */
/* $Id: onstack.h,v 2.7 2006/09/15 20:40:39 ed Exp $ */

#ifndef _ONSTACK_H_
#define _ONSTACK_H_
/* include after ncconfig.h */
/**
 * This file provides definitions which allow us to
 * "allocate" arrays on the stack where possible.
 * (Where not possible, malloc and free are used.)
 *
 * The macro ALLOC_ONSTACK(name, type, nelems) is used to declare 
 * an array of 'type' named 'name' which is 'nelems' long.
 * FREE_ONSTACK(name) is placed at the end of the scope of 'name'
 * to call 'free' if necessary.
 * 
 * The macro ALLOC_ONSTACK wraps a call to alloca() on most systems.
 */

#if HAVE_ALLOCA
/*
 * Implementation based on alloca()
 */

#if defined(__GNUC__)
# if !defined(alloca)
# define alloca __builtin_alloca
# endif
#else
# if HAVE_ALLOCA_H
#  include <alloca.h>
# elif defined(_AIX)
#  pragma alloca
# endif /* HAVE_ALLOCA_H */
#endif /* __GNUC__ */

# if !defined(ALLOCA_ARG_T)
# define ALLOCA_ARG_T int /* the usual type of the alloca argument */
# endif

# define ALLOC_ONSTACK(name, type, nelems) \
	type *const name = (type *) alloca((ALLOCA_ARG_T)((nelems) * sizeof(type)))

# define FREE_ONSTACK(name)

#elif defined(_CRAYC) && !defined(__crayx1) && !__cplusplus && __STDC__ > 1
/*
 * Cray C allows sizing of arrays with non-constant values.
 */

# define ALLOC_ONSTACK(name, type, nelems) \
	type name[nelems]

# define FREE_ONSTACK(name)

#else
/*
 * Default implementation. When all else fails, use malloc/free.
 */

# define ALLOC_ONSTACK(name, type, nelems) \
	type *const name = (type *) malloc((nelems) * sizeof(type))

# define FREE_ONSTACK(name) \
	free(name)

#endif
	
#endif /* _ONSTACK_H_ */