Use 'constexpr' when including pio header files from a C++ compiler #2651

Merged
rhulme merged 3 commits from develop into develop 2026-03-02 14:12:14 -06:00
rhulme commented 2025-09-06 09:26:18 -05:00 (Migrated from github.com)

In particular this allows compile-time checks to be performed on the contents of pio_program structs via 'static_assert'.

This could be used (for example) to confirm that multiple PIO programs fit in a single PIO module and abort compilation if not.

Fixes #2650

In particular this allows compile-time checks to be performed on the contents of pio_program structs via 'static_assert'. This could be used (for example) to confirm that multiple PIO programs fit in a single PIO module and abort compilation if not. Fixes #2650
lurch (Migrated from github.com) reviewed 2025-09-08 06:53:59 -05:00
@ -79,6 +79,13 @@ struct c_sdk_output : public output_format {
fprintf(out, "#endif\n");
lurch (Migrated from github.com) commented 2025-09-08 06:53:59 -05:00

https://en.cppreference.com/w/cpp/language/constexpr.html says that constexpr was only added in C++11, so should this line perhaps be

        fprintf(out, "#if defined(__cplusplus) && defined(__cpp_constexpr)\n");

so that it doesn't break older C++ compilers? (Or perhaps simply #ifdef __cpp_constexpr is sufficient?)

https://en.cppreference.com/w/cpp/language/constexpr.html says that `constexpr` was only added in C++11, so should this line perhaps be ```suggestion fprintf(out, "#if defined(__cplusplus) && defined(__cpp_constexpr)\n"); ``` so that it doesn't break older C++ compilers? (Or perhaps simply `#ifdef __cpp_constexpr` is sufficient?)
rhulme (Migrated from github.com) reviewed 2025-09-13 03:46:25 -05:00
@ -79,6 +79,13 @@ struct c_sdk_output : public output_format {
fprintf(out, "#endif\n");
rhulme (Migrated from github.com) commented 2025-09-13 03:46:25 -05:00

Yes, fair point. I've update the check.

Yes, fair point. I've update the check.
kilograham (Migrated from github.com) reviewed 2025-09-15 13:02:26 -05:00
kilograham (Migrated from github.com) approved these changes 2026-03-02 14:12:07 -06:00
Sign in to join this conversation.
No reviewers
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!2651
No description provided.