diff --git a/platforms/posix/src/px4/windows/runtime/init.cpp b/platforms/posix/src/px4/windows/runtime/init.cpp index c90249974e..d2cd8592fc 100644 --- a/platforms/posix/src/px4/windows/runtime/init.cpp +++ b/platforms/posix/src/px4/windows/runtime/init.cpp @@ -95,15 +95,26 @@ volatile LONG g_px4_session_id = 0; * call. They live at file scope because every translation unit that * includes on Windows references them through the inline body * of usleep(). */ -extern "C" long g_usleep_pure_spin_us = 5000; -extern "C" long g_usleep_spin_tail_us = 1000; +/* GCC's -Werror trips on `extern name = init;` because an + * initializer turns the line into a definition, making `extern` + * redundant. The matching `extern` declarations live in + * platforms/posix/include/windows_shim/unistd.h; here we only need + * definitions with external linkage (the default for non-static globals + * at namespace scope). Wrapping in `extern "C"` keeps the C linkage that + * the inline shim relies on. */ +extern "C" { + long g_usleep_pure_spin_us = 5000; + long g_usleep_spin_tail_us = 1000; +} /* Floor for the per-thread adaptive spin tail. Initialised by * px4_windows_calibrate_usleep_threshold() to the host-measured P95 * waitable-timer jitter so the controller never collapses below the * value we already know is needed to cover the observed long-tail wakes. * Defaults to a conservative 700 us when calibration cannot run (e.g. * pre-1803 Windows with no high-resolution timer). */ -extern "C" long g_usleep_adaptive_min_tail_us = 700; +extern "C" { + long g_usleep_adaptive_min_tail_us = 700; +} /** * @brief Auto-tune g_usleep_pure_spin_us against the host's measured diff --git a/src/lib/parameters/templates/px4_parameters.hpp.jinja b/src/lib/parameters/templates/px4_parameters.hpp.jinja index ca13a7bb93..c215552185 100644 --- a/src/lib/parameters/templates/px4_parameters.hpp.jinja +++ b/src/lib/parameters/templates/px4_parameters.hpp.jinja @@ -2,6 +2,7 @@ #include // NAN +#include #include #include @@ -38,17 +39,21 @@ static constexpr param_type_t parameters_type[] = { {%- endfor -%} }; -static constexpr params parameters_volatile[] = { +{# Use std::array so that an empty list (size 0) is well-formed on all + compilers. A C-style "T arr[] = {}" is a GCC/Clang extension; MSVC + rejects it with C2466 ("cannot allocate an array of constant size 0"). + std::array is standard and supports range-for. #} +static constexpr std::array parameters_volatile = { { {% for param in volatile_params %} params::{{ param.attrib["name"] }}, {% endfor %} -}; +} }; -static constexpr params parameters_readonly[] = { +static constexpr std::array parameters_readonly = { { {% for param_name in readonly_param_names %} params::{{ param_name }}, {% endfor %} -}; +} }; } // namespace px4