This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Error with nrfx_gpiote.h, offsetof, IAR, and C++

I am trying to use C++ with an nRF5 board, but I'm running into issues with the MDK, IAR (v8.40.2), and C++. When I try to include "nrfx_gpiote.h" in a .cpp file, I get the following errors (this is from the examples\peripherals\gpiote with main.c switched to main.cpp:

Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_gpiote.h 84
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_gpiote.h 85
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_gpiote.h 86
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_gpiote.h 88
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_gpiote.h 89
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_gpiote.h 90
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_gpiote.h 91
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 129
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 130
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 131
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 132
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 133
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 134
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 136
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 137
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 138
Error[Pe028]: expression must have a constant value C:\nRF5_SDK_16.0.0\modules\nrfx\hal\nrf_ppi.h 139

Does anyone know why offsetof seems to be failing after the first offsetof in these files only with IAR and C++? I can't get a more minimal reproduction, as IAR will compile (with iccarm.exe -e --c++ test.cpp) even this:

#include <stddef.h>

extern "C"
{
    typedef struct test
    {
        int a;
        int b;
    } test_t;

    typedef enum
    {
        A = offsetof(test_t, a),
        B = offsetof(test_t, b),
    } test_field_t;
}
without issue. It's only when done as part of the larger SDK that it seems to fail. If I include this file from anything with a .c extension there is no issue.
EDIT: Adding IAR version
EDIT2: After speaking with IAR, it seems like this is fixed in IAR 8.50.2. I don't know if this matters for previous versions though. Still trying to find the root cause though.
Parents Reply Children
Related