Developer documentation
Version 3.0.3-105-gd3941f44
Variable-length array macros

Macros

#define VLA(name, type, num)   type name[num]
 
#define VLA_MAX(name, type, num, max)   type name[num]
 
#define NON_POD_VLA(name, type, num)   type name[num]
 
#define NON_POD_VLA_MAX(name, type, num, max)   type name[num]
 

Detailed Description

The reason for defining these macros at all is that VLAs are not part of the C++ standard, and not available on all compilers. Regardless of the availability of VLAs, they should be avoided if possible since they run the risk of overrunning the stack if the length of the array is large, or if the function is called recursively. They can be used safely in cases where the size of the array is expected to be small, and the function will not be called recursively, and in these cases may avoid the overhead of allocation that might be incurred by the use of e.g. a vector.

Macro Definition Documentation

◆ NON_POD_VLA

#define NON_POD_VLA (   name,
  type,
  num 
)    type name[num]

define a variable-length array of non-POD data if supported by the compiler, or a vector otherwise. This may have performance implications in the latter case if this forms part of a tight loop.

See also
VLA_MAX

Definition at line 147 of file types.h.

◆ NON_POD_VLA_MAX

#define NON_POD_VLA_MAX (   name,
  type,
  num,
  max 
)    type name[num]

define a variable-length array of non-POD data if supported by the compiler, or a fixed-length array of size max otherwise. This may have performance implications in the latter case if this forms part of a tight loop.

Note
this should not be used in recursive functions, unless the maximum number of calls is known to be small. Large amounts of recursion will run the risk of overrunning the stack.
See also
VLA

Definition at line 148 of file types.h.

◆ VLA

#define VLA (   name,
  type,
  num 
)    type name[num]

define a variable-length array (VLA) if supported by the compiler, or a vector otherwise. This may have performance implications in the latter case if this forms part of a tight loop.

See also
VLA_MAX

Definition at line 118 of file types.h.

◆ VLA_MAX

#define VLA_MAX (   name,
  type,
  num,
  max 
)    type name[num]

define a variable-length array if supported by the compiler, or a fixed-length array of size max otherwise. This may have performance implications in the latter case if this forms part of a tight loop.

Note
this should not be used in recursive functions, unless the maximum number of calls is known to be small. Large amounts of recursion will run the risk of overrunning the stack.
See also
VLA

Definition at line 119 of file types.h.