Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zx64 opened this issue Apr 15, 2025 · 0 comments · May be fixed by #2438
Open

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

zx64 opened this issue Apr 15, 2025 · 0 comments · May be fixed by #2438

Comments

@zx64
Copy link

zx64 commented Apr 15, 2025

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 \
       }
@brokeh brokeh linked a pull request Apr 23, 2025 that will close this issue
@lurch lurch linked a pull request Apr 23, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants