c++avravr-gcc

designator order for field '__file::flags' does not match the declaration order in 'FILE'


I'm trying to compile a binary with avr-g++ using this tutorial for UART, but during compilation, I get the following error:

main.cpp:50:20: error: designator order for field '__file::flags' does not match declaration order in 'FILE'
   50 | FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);

I've made sure that I'm using /usr/avr/include/stdio.h, and attempted to use C++20 in light of the following:

Why does C++11 not support designated initializer lists as C99?

Yet I have not been able to have any success in compiling (or even understanding the problem). I have also attempted to replicate the example in the avr stdio.h implementation source file (line 152) but also had no success.

Any help is greatly appreciated. Thanks in advance.

EDIT: This got fixed as suggested here.


Solution

  • As it appears, FDEV_SETUP_STREAM is not ready for C++, see also example non-trivial designated initializers not supported for the reason behind the error.

    What works for me is to re-define FDEV_SETUP_STREAM to include all components of struct __file in their respective order:

    #undef FDEV_SETUP_STREAM
    #define FDEV_SETUP_STREAM(p, g, f) \
        {                              \
            .buf = NULL,               \
            .unget = 0,                \
            .flags = f,                \
            .size = 0,                 \
            .len = 0,                  \
            .put = p,                  \
            .get = g,                  \
            .udata = 0                 \
        }
    

    However, the behaviour of the compiler appears to be not really consistent about when that error is raised.

    Here is the according AVR-LibC issue #898 fixed in AVR-LibC v2.2.0.