[Development] better compile-time os detection
Thiago Macieira
thiago.macieira at intel.com
Fri Jul 24 07:36:19 CEST 2026
On Thursday, 23 July 2026 19:20:41 Pacific Daylight Time EXT Tim Blechmann via
Development wrote:
> depending on the code, one could utilize tag dispatching, so only then
> overload declarations would require the preprocessor.
> ```
> #ifdef LINUX
> auto rename(auto src, auto target, Os::LinuxT) {
> return renameat2(...);
> }
> #elif DARWIN
> auto rename(auto src, auto target, Os::DarwinT) {
> return renameatx_np(...);
> }
> #endif
>
> auto rename(auto src, auto target)
> {
> return rename(src, target, Os::Current); // no ifdef
> }
> ```
Why would you do that? What's the advantage? If you remove the tag, it would
compile to the same thing.
> it is mainly useful for cases where no platform-specific APIs are
> involved, but one still wants to do per-platform decisions.
Right, things like "does this platform use .so suffix or .dylib?" Those aren't
detections, they are defaults we apply.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Principal Engineer - Intel DCG - Platform & Sys. Eng.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5176 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20260723/e4c4126e/attachment.bin>
More information about the Development
mailing list