News for hackers. Stuff that matters.
Re:Trying out C++20's modules with Clang and Make by maccard on Sunday October 15, 2023 @03:33PM (#37892682)
You're really burying the lede here.

Headers are literal copy paste, and are entirely different. Anyone who has ever had to define WIN32_LEAN_AND_MEAN knows that there's _way_ more going on here.

Re:Trying out C++20's modules with Clang and Make by dagmx on Sunday October 15, 2023 @05:00PM (#37893334)
This exactly, thank you. Sometimes you can’t untangle the defines in another header and they infect your own.

Modules are a nice barrier to guard against side effects.

Re:Trying out C++20's modules with Clang and Make by mathstuf on Sunday October 15, 2023 @05:32PM (#37893573)
Yes, the number of times I've had a `LoadLibrary` function name conflict with `windows.h`'s `A`/`W` suffix-switching or had to deal with X11's `#define Status int` "typedef" mucking with completely unrelated code is…sad.
Re:Trying out C++20's modules with Clang and Make by mgaunard on Monday October 16, 2023 @03:52AM (#37896894)
Just don't include those in headers.
Re:Trying out C++20's modules with Clang and Make by maccard on Monday October 16, 2023 @04:46AM (#37897197)
That's not possible. Windows.h is a requirement for anyone working on Windows. Various standard library implementations make use of macros to implement debug-only assertions, or bounds checks in containers.
Re:Trying out C++20's modules with Clang and Make by mgaunard on Monday October 16, 2023 @05:49AM (#37897595)
Don't include it in headers = only include it in a .cpp file.
Re:Trying out C++20's modules with Clang and Make by mathstuf on Monday October 16, 2023 @08:42AM (#37899047)
Because `void*` to pass `HANDLE` around is better how? Maybe if you're able to hermetically seal off platform-specific bits, but usually you'll have two parts that want to talk about Windows API types across their call boundaries…
Re:Trying out C++20's modules with Clang and Make by mgaunard on Monday October 16, 2023 @04:51PM (#37906432)
It's called encapsulation.
Re:Trying out C++20's modules with Clang and Make by mathstuf on Tuesday October 17, 2023 @09:10AM (#37914410)
Sure, but I also prefer talking directly about what you're talking about though. If you have some Windows implementations that need to talk to each other, I'd rather they use HANDLE and HMODULE than "void* winkwinknudgenudge" style things. Hopefully users don't need to include these headers directly (but sometimes they do), but it's still something you need to consider in the APIs and such because while the header might say LoadLibrary, the caller is going to need to include windows.h and deal with the #define anyways.
Re:Trying out C++20's modules with Clang and Make by mgaunard on Tuesday October 17, 2023 @03:16PM (#37920183)
any interaction with the win32 api should be hidden within your library.

Surely you want your code to be portable to begin with?

Re:Trying out C++20's modules with Clang and Make by mathstuf on Tuesday October 17, 2023 @08:11PM (#37923298)
It can be portable and still want to expose native information. SDL2 is probably something we can all agree is portable, but this still exists: https://wiki.libsdl.org/SDL2/SDL_SysWMmsg