Skip to content

Preprocessor Macros lead to compiler errors #9321

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

Closed
1 task done
insunaa opened this issue Mar 2, 2024 · 5 comments · Fixed by #9323
Closed
1 task done

Preprocessor Macros lead to compiler errors #9321

insunaa opened this issue Mar 2, 2024 · 5 comments · Fixed by #9323
Assignees
Labels
Status: In Progress ⚠️ Issue is in progress Type: Feature request Feature request for Arduino ESP32
Milestone

Comments

@insunaa
Copy link

insunaa commented Mar 2, 2024

Board

LilyGo TTGO LoRa32

Device Description

Just a TTGO

Hardware Configuration

Not relevant

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Linux

Flash frequency

not relevant

PSRAM enabled

yes

Upload speed

not relevant

Description

In cores/esp32/binary.h

#define B1 1

Causes compilation issues when Arduino.h is included in any project where the literal B1 already means something.

With newer versions of fmtlib/fmt

problems are also caused by

#define F(string_literal) (FPSTR(PSTR(string_literal)))

Example: using&including fmtlib/fmt where it's used as a template typename

template <bool B = false> constexpr auto count() -> size_t { return B ? 1 : 0; }
template <bool B1, bool B2, bool... Tail> constexpr auto count() -> size_t {
  return (B1 ? 1 : 0) + count<B2, Tail...>();
}

Sketch

#include <fmt/core.h>
#include "Arduino.h"

Debug Message

~/.platformio/packages/framework-arduinoespressif32/cores/esp32/binary.h:31:12: error: expected '>' before numeric constant
.pio/libdeps/TTGO-MQTT-lora32-v1/fmt/include/fmt/core.h:1118:58: error: redefinition of 'template<bool <anonymous> > constexpr size_t fmt::v8::detail::count()'

Other Steps to Reproduce

Could this be handled by an enum instead?

namespace arduino {
    enum Binary : uint32_t {
        B0 = 0,
        B00 = 0,
        B000 = 0,
        B0000 = 0,
        B00000 = 0,
        .
        .
        .
    };
};

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@insunaa insunaa added the Status: Awaiting triage Issue is waiting for triage label Mar 2, 2024
@Jason2866
Copy link
Collaborator

For what is this file there in general?

@insunaa
Copy link
Author

insunaa commented Mar 2, 2024

I have absolutely no idea, but it's there in the reference Arduino API, too. Tho they use namespaces and enums appropriately:
https://github.com/arduino/ArduinoCore-API/blob/master/api/Binary.h

@Jason2866
Copy link
Collaborator

Why not open a PR and replace the current with the one you linked?

@insunaa
Copy link
Author

insunaa commented Mar 2, 2024

Because I don't know if it will break things. I don't usually develop for Arduino.
It doesn't break things in my own project, because in my own project I can just delete the
#include "binary.h" line from Arduino.h and everything works fine, but I have no idea what the impact would be on projects that actually use these

@Jason2866 Jason2866 added Type: Feature request Feature request for Arduino ESP32 and removed Status: Awaiting triage Issue is waiting for triage labels Mar 2, 2024
@Jason2866
Copy link
Collaborator

Jason2866 commented Mar 2, 2024

There is a reference from Arduino. This is an Arduino implementation. So the change is getting closer to the API :-)
And this will go in v3.0.0 which has many breaking changes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress ⚠️ Issue is in progress Type: Feature request Feature request for Arduino ESP32
Projects
Development

Successfully merging a pull request may close this issue.

3 participants