binary_info doesn't compile in C++ code #2425

Closed
opened 2025-04-15 08:40:33 -05:00 by zx64 · 1 comment
zx64 commented 2025-04-15 08:40:33 -05:00 (Migrated from github.com)

Version info:
Pico-SDK develop branch (5592322)
arm-none-eabi-gcc (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 13.3.1 20240614

Steps to reproduce:
Get the pico-examples repository
Rename either of the binary_info examples to have a .cpp extension and update the corresponding CMakeLists.txt
Build that example:

In file included from /pico/pico-sdk/src/common/pico_binary_info/include/pico/binary_info.h:30,
                 from /pico/pico-examples/binary_info/hello_anything/hello_anything.cpp:9:
/pico/pico-examples/binary_info/hello_anything/hello_anything.cpp: In function 'int main()':
/pico/pico-examples/binary_info/hello_anything/hello_anything.cpp:15:13: error: designator order for field '_binary_info_named_group::flags' does not match declaration order in 'const _binary_info_named_group'
   15 |     bi_decl(bi_program_feature_group(0x1111, 0, "UART Configuration"));
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
/pico/pico-examples/binary_info/hello_anything/hello_anything.cpp:16:13: error: designator order for field '_binary_info_named_group::flags' does not match declaration order in 'const _binary_info_named_group'
   16 |     bi_decl(bi_program_feature_group(0x1111, 1, "Enabled Interfaces"));
      |             ^~~~~~~~~~~~~~~~~~~~~~~~

C++ has stricter requirements for designated initialisers: cppref

Note: out-of-order designated initialization, nested designated initialization, mixing of designated initializers and regular initializers, and designated initialization of arrays are all supported in the C programming language, but are not allowed in C++.

This can be resolved by changing the __bi_named_group macro so flags and group_tag are initialised in the same order they are declared in the _binary_info_named_group structure:

  diff --git a/src/common/pico_binary_info/include/pico/binary_info/code.h b/src/common/pico_binary_info/include/pico/binary_info/code.  h
  index 63239a9..b7fedc9 100644
  --- a/src/common/pico_binary_info/include/pico/binary_info/code.h
  +++ b/src/common/pico_binary_info/include/pico/binary_info/code.h
  @@ -156,8 +156,8 @@ static const struct _binary_info_named_group __bi_lineno_var_name = { \
               .tag = _parent_tag, \
           },\
           .parent_id = _parent_id, \
  -        .group_tag = _group_tag, \
           .flags = _flags, \
  +        .group_tag = _group_tag, \
           .group_id = _group_id, \
           .label = _label \
       }
Version info: Pico-SDK `develop` branch (5592322) arm-none-eabi-gcc (Arm GNU Toolchain 13.3.Rel1 (Build arm-13.24)) 13.3.1 20240614 Steps to reproduce: Get the `pico-examples` repository Rename either of the `binary_info` examples to have a `.cpp` extension and update the corresponding `CMakeLists.txt` Build that example: ``` In file included from /pico/pico-sdk/src/common/pico_binary_info/include/pico/binary_info.h:30, from /pico/pico-examples/binary_info/hello_anything/hello_anything.cpp:9: /pico/pico-examples/binary_info/hello_anything/hello_anything.cpp: In function 'int main()': /pico/pico-examples/binary_info/hello_anything/hello_anything.cpp:15:13: error: designator order for field '_binary_info_named_group::flags' does not match declaration order in 'const _binary_info_named_group' 15 | bi_decl(bi_program_feature_group(0x1111, 0, "UART Configuration")); | ^~~~~~~~~~~~~~~~~~~~~~~~ /pico/pico-examples/binary_info/hello_anything/hello_anything.cpp:16:13: error: designator order for field '_binary_info_named_group::flags' does not match declaration order in 'const _binary_info_named_group' 16 | bi_decl(bi_program_feature_group(0x1111, 1, "Enabled Interfaces")); | ^~~~~~~~~~~~~~~~~~~~~~~~ ``` C++ has stricter requirements for designated initialisers: [cppref](https://en.cppreference.com/w/cpp/language/aggregate_initialization#Designated_initializers) > Note: out-of-order designated initialization, nested designated initialization, mixing of designated initializers and regular initializers, and designated initialization of arrays are all supported in the [C programming language](https://en.cppreference.com/w/c/language/struct_initialization), but are not allowed in C++. This can be resolved by changing the `__bi_named_group` macro so `flags` and `group_tag` are initialised in the same order they are declared in the `_binary_info_named_group` structure: ``` diff --git a/src/common/pico_binary_info/include/pico/binary_info/code.h b/src/common/pico_binary_info/include/pico/binary_info/code. h index 63239a9..b7fedc9 100644 --- a/src/common/pico_binary_info/include/pico/binary_info/code.h +++ b/src/common/pico_binary_info/include/pico/binary_info/code.h @@ -156,8 +156,8 @@ static const struct _binary_info_named_group __bi_lineno_var_name = { \ .tag = _parent_tag, \ },\ .parent_id = _parent_id, \ - .group_tag = _group_tag, \ .flags = _flags, \ + .group_tag = _group_tag, \ .group_id = _group_id, \ .label = _label \ } ```
lurch commented 2025-05-06 06:10:41 -05:00 (Migrated from github.com)

Fix merged into develop

Fix merged into `develop`
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#2425
No description provided.