Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

onstack.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright 1997, University Corporation for Atmospheric Research
00003  *      See netcdf/COPYRIGHT file for copying and redistribution conditions.
00004  */
00005 
00006 #ifndef _ONSTACK_H_
00007 #define _ONSTACK_H_
00008 /* include after ncconfig.h */
00009 /**
00010  * This file provides definitions which allow us to
00011  * "allocate" arrays on the stack where possible.
00012  * (Where not possible, malloc and free are used.)
00013  *
00014  * The macro ALLOC_ONSTACK(name, type, nelems) is used to declare 
00015  * an array of 'type' named 'name' which is 'nelems' long.
00016  * FREE_ONSTACK(name) is placed at the end of the scope of 'name'
00017  * to call 'free' if necessary.
00018  * 
00019  * The macro ALLOC_ONSTACK wraps a call to alloca() on most systems.
00020  */
00021 
00022 #if HAVE_ALLOCA
00023 /*
00024  * Implementation based on alloca()
00025  */
00026 
00027 #if defined(__GNUC__)
00028 # if !defined(alloca)
00029 # define alloca __builtin_alloca
00030 # endif
00031 #else
00032 # if HAVE_ALLOCA_H
00033 #  include <alloca.h>
00034 # elif defined(_AIX)
00035 #  pragma alloca
00036 # endif /* HAVE_ALLOCA_H */
00037 #endif /* __GNUC__ */
00038 
00039 # if !defined(ALLOCA_ARG_T)
00040 # define ALLOCA_ARG_T int /* the usual type of the alloca argument */
00041 # endif
00042 
00043 # define ALLOC_ONSTACK(name, type, nelems) \
00044         type *const name = (type *) alloca((ALLOCA_ARG_T)((nelems) * sizeof(type)))
00045 
00046 # define FREE_ONSTACK(name)
00047 
00048 #elif defined(_CRAYC) && !__cplusplus && __STDC__ > 1
00049 /*
00050  * Cray C allows sizing of arrays with non-constant values.
00051  */
00052 
00053 # define ALLOC_ONSTACK(name, type, nelems) \
00054         type name[nelems]
00055 
00056 # define FREE_ONSTACK(name)
00057 
00058 #else
00059 /*
00060  * Default implementation. When all else fails, use malloc/free.
00061  */
00062 
00063 # define ALLOC_ONSTACK(name, type, nelems) \
00064         type *const name = (type *) malloc((nelems) * sizeof(type))
00065 
00066 # define FREE_ONSTACK(name) \
00067         free(name)
00068 
00069 #endif
00070         
00071 #endif /* _ONSTACK_H_ */
 

Powered by Plone

This site conforms to the following standards: