Skip to content
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

Defined macro names collide because they're very common #85

Open
hadrielk opened this issue Jun 28, 2023 · 0 comments
Open

Defined macro names collide because they're very common #85

hadrielk opened this issue Jun 28, 2023 · 0 comments

Comments

@hadrielk
Copy link

We're using an older version of TANK than the current head, but it looks like the problem persists even now...

tank_client.h #includes Switch/switch.h, which #defines the following macro names:

#define require(x) assert(x)
#define Drequire(x) assert(x)
#define EXPECT(x) assert(x)
#define DEXPECT(x) assert(x)

...

#define sizeof_array(x) sizeof(detail::SIZEOF_ARRAY_REQUIRES_ARRAY_ARGUMENT(x))

#define STRLEN(p) (uint32_t)(sizeof(p) - 1)
#define STRWITHLEN(p) (p), (uint32_t)(sizeof(p) - 1)
#define LENWITHSTR(p) (uint32_t)(sizeof(p) - 1), (p)
#define STRWLEN(p) STRWITHLEN(p)
#define LENWSTR(p) LENWITHSTR(p)
#define _S(p) STRWITHLEN(p)

...

#define TOKEN_PASTE(x, y) x##y
#define TOKEN_PASTE2(x, y) TOKEN_PASTE(x, y)

#define DEFER(...) auto TOKEN_PASTE2(__deferred, __COUNTER__) = make_scope_guard([&] { __VA_ARGS__; });

But those are very common tokens/names, and will cause collisions with names by consuming user code, as well as other libraries.

For example boost/asio uses require() as a regular C++ function name.

Since macro names are not namespaced, the usual thing to do is prefix them with library name. E.g., TANK_REQUIRE and TANK_EXPECT, etc.

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

No branches or pull requests

1 participant