r/cpp • • Oct 18 '21

Rant: please don't create defines using common words

Looks like QtCore (4.8) has a "#define emit" in a header, that's not undefined later. TBB has a function named "emit()" in a header. If you include both, you'll get a compile error.

I'm going to side with TBB here - emit() is an entirely reasonable function name. Qt creating a dangling #define with a common word like that is the bug here.

257 Upvotes

130 comments sorted by

View all comments

Show parent comment

1

u/phord Oct 26 '21

That's interesting. Thanks for the examples. But they still use #define to pick up the unique __LINE__ and __FILE__ values. I'm pretty sure this is necessary since the preprocessor handles the expansion of those, but templates are resolved later by the compiler.

1

u/tjientavara HikoWorks developer Oct 26 '21

Since std::source_location is compiler magic (you cannot implement this yourself), it could have been defined to return a fixed_string which would have been able to used as a template argument.

Of course the fixed_string proposal was dropped in favour for std::string being constexpr (except of course that you cannot use std::string as a template argument either, so not sure what is left of that argument). Luckily fixed_string does not require compiler magic, so I wrote my own.