Skip to content

Preprocessor Macros lead to compiler errors #9321

Closed
@insunaa

Description

@insunaa

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions