Skip to content

Fix macro collision: Replace print macros with inline template functions - #335

Open
berni2612 wants to merge 1 commit into
thelsing:masterfrom
berni2612:master
Open

Fix macro collision: Replace print macros with inline template functions#335
berni2612 wants to merge 1 commit into
thelsing:masterfrom
berni2612:master

Conversation

@berni2612

Copy link
Copy Markdown

Motivation

When compiling the thelsing/knx library in environments like ESP-IDF or ESPHome, it is often necessary to define KNX_NO_PRINT to avoid conflicts with the host framework's UART implementation.

The Issue

Currently, when KNX_NO_PRINT is defined, the library falls back to C-style preprocessor macros:
#define print(...) do {} while(0)

This aggressive macro replacement causes severe naming collisions. If the host framework (e.g., ESP-IDF or ESPHome core files) uses print or println as legitimate method names inside other classes, the preprocessor blindly replaces them, resulting in fatal expected unqualified-id before 'do' compilation errors.

The Solution

This PR replaces the #define macros in bits.h with empty static inline void template functions.
This achieves the exact same zero-overhead behavior when KNX_NO_PRINT is active, but safely respects C++ namespaces and class scopes, completely resolving the compilation errors in ESPHome/ESP-IDF integrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant