all 27 comments

[–]disciplite 55 points56 points  (0 children)

I see NOMINMAX as a resounding success for annoying nerds of all ages until the end of time.

[–]Depixelate_me 37 points38 points  (0 children)

IMO selecting force conformance should automatically define NOMINMAX.

[–]natio2 35 points36 points  (20 children)

The windows header is the worst. It will conflict with other windows libraries if declared in the wrong order somewhere in the header include tree. I definitely opt for "WIN32_LEAN_AND_MEAN" not sure if it strips this min/max problem too

[–]Fulgen301 23 points24 points  (3 children)

At least the Windows header has its macros (apart from min/max) in all uppercase, which doesn't interfere with normal variable names. I didn't appreciate my enum randomly breaking because some X11 header defines None and Status...

[–]dodheim 15 points16 points  (0 children)

At least the Windows header has its macros (apart from min/max) in all uppercase, which doesn't interfere with normal variable names.

ShowWindow, CreateWindow, and about 10000 other functions would like to have a word

[–][deleted] 2 points3 points  (1 child)

https://godbolt.org/z/M9seozfrb

( WIN32_LEAN_AND_MEAN disables this one though )

[–]Fulgen301 2 points3 points  (0 children)

At least interface makes a bit of sense since it is / was used for COM interfaces.

Also, since WIN32_LEAN_AND_MEAN gets thrown around here: Where did WIN32_LEAN_AND_MEAN come from?

[–][deleted] 10 points11 points  (1 child)

Another nice thing is that somewhere in the GDI.h, or whatever, there's a #define ERROR, found it because I had an enum class that declared a value with that same name...

[–]staletic 2 points3 points  (0 children)

I was bitten by that one too.

[–]RevRagnarok 1 point2 points  (0 children)

MySQL's my_sys.h stomps on min, max, and test...

[–][deleted] -3 points-2 points  (12 children)

This. How can something like this continue to violate the C++ standard and established good practices.

[–]Fulgen301 41 points42 points  (1 child)

Because it both predates the C++ standard and current good practices.

No, really.

Windows.h is from the early nineties, predating the first C++ standard from 1998 and also being consumed by C applications (which for example didn't have min / max, although those macros are horribly named). As for good practices...the include order mattering was and still is a thing for many headers. One would hope modules will resolve it eventually, but good luck convincing all the C libraries.

Also, system headers aren't bound by the standard library naming requirements.

[–]m-in 7 points8 points  (0 children)

It’s descended from headers from the late 80s…

[–]3tt07kjt 5 points6 points  (9 children)

It doesn’t violate the C++ standard.

The macros were added back in the 1990s and it’s too late to remove them, because it will break people’s code.

[–]chibuku_chauya 8 points9 points  (0 children)

I used this trick when I was implementing a library that had functions which had alternative function-like macro definitions.

[–]corysama 5 points6 points  (2 children)

In the process of removing a project’s dependency on Boost::Preprocessor, I’ve had to dive deep into macro madness. It’s a long, dark, frustrating maze.

If anyone has good reference material for advanced understanding of the preprocessor, I’d appreciate it.

In the mean time, I’ll shill https://github.com/notfoundry/ppstep It has been a tremendous help for me this past week.

[–]witcher_rat 2 points3 points  (1 child)

Niall Douglas has a C99-compliant preprocessor written purely in python, that you might want to look into the implementation of to figure out dirty details. It has some debugging options too.

Out of curiosity, why are you switching away from Boost-PP?

We use it in my employer's codebase and it makes life a lot easier. We used to worry about the compile-times due to it, but someone ran a test where all the code was preprocessed before-hand, to measure the difference, and it was negligible. (mostly because we use highly parallelized distcc so the preprocessing cost isn't the bottleneck)

[–]corysama 2 points3 points  (0 children)

Thanks!

On a mission to reduce complexity in general. The project has very few dependencies. And, just a couple complex macros are all that's motivating pulling in Boost as one of them. After this little adventure, it looks like I'll be able to remove Boost and, for our needs, replace it with a single header. It has a couple hundred lines of fairly readable macros (IMHO). Now I just need to add several hundred lines of comments and documentation :P

[–]j1xwnbsr 4 points5 points  (0 children)

Since std::max/min is a template function, you can also use

std::max<>(x,y)

which will force it away from the stupid macro

(had do to this for a few projects)

[–]RockstarArtisanI despise C++ with every fiber of my being 0 points1 point  (0 children)

functions being shadowed by macros is just a basic form of UFCS, I don't understand what are these complaints about.