VLAs unsupported in Visual Studio

Issue #178 resolved
Andrew Melim created an issue

YAWB (yet another windows bug)

The following code is not permitted in visual studio since it does not support c99 style variable length arrays at compile time. Since there is a note regarding perf, this seems to be a decision to be made whether to rewrite for compatibility (i.e. using dynamically allocated memory)

  /**
   * @brief Return value and derivatives, reverse AD version
   * This very unsafe method needs a JacobianMap with correctly allocated
   * and initialized VerticalBlockMatrix, hence is declared private.
   */
  T value(const Values& values, JacobianMap& jacobians) const {
    // The following piece of code is absolutely crucial for performance.
    // We allocate a block of memory on the stack, which can be done at runtime
    // with modern C++ compilers. The traceExecution then fills this memory
    // with an execution trace, made up entirely of "Record" structs, see
    // the FunctionalNode class in expression-inl.h
    size_t size = traceSize();
    ExecutionTraceStorage traceStorage[size];
    ExecutionTrace<T> trace;
    T value(traceExecution(values, trace, traceStorage));
    trace.startReverseAD1(jacobians);
    return value;
  }

Specific error:

3>C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(209): error C2057: expected constant expression
3>          C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(202) : while compiling class template member function 'gtsam::Point2 gtsam::Expression<gtsam::Point2>::value(const gtsam::Values &,gtsam::JacobianMap &) const'
3>          C:\Users\water_000\borg\gtsam\gtsam_unstable/nonlinear/ExpressionFactor.h(107) : see reference to function template instantiation 'gtsam::Point2 gtsam::Expression<gtsam::Point2>::value(const gtsam::Values &,gtsam::JacobianMap &) const' being compiled
3>          C:\Users\water_000\borg\gtsam\gtsam_unstable/slam/expressions.h(22) : see reference to class template instantiation 'gtsam::Expression<gtsam::Point2>' being compiled
3>C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(209): error C2466: cannot allocate an array of constant size 0
3>C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(209): error C2133: 'traceStorage' : unknown size
4>C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(209): error C2057: expected constant expression
4>          C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(202) : while compiling class template member function 'gtsam::Pose2 gtsam::Expression<gtsam::Pose2>::value(const gtsam::Values &,gtsam::JacobianMap &) const'
4>          C:\Users\water_000\borg\gtsam\gtsam_unstable/nonlinear/ExpressionFactor.h(107) : see reference to function template instantiation 'gtsam::Pose2 gtsam::Expression<gtsam::Pose2>::value(const gtsam::Values &,gtsam::JacobianMap &) const' being compiled
4>          ..\..\..\gtsam_unstable\examples\Pose2SLAMExampleExpressions.cpp(41) : see reference to class template instantiation 'gtsam::Expression<gtsam::Pose2>' being compiled
4>C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(209): error C2466: cannot allocate an array of constant size 0
4>C:\Users\water_000\borg\gtsam\gtsam/nonlinear/Expression.h(209): error C2133: 'traceStorage' : unknown size

Tagging @dellaert

Comments (5)

  1. Frank Dellaert

    It's just one malloc, but I'd still just bracket with a compiler version and allocate on the heap for that compiler (not I suspect using an Intel compiler on windows will do just fine).

  2. Log in to comment