简体   繁体   English

C ++头文件中的#ifdef __linux和#ifdef __unix之间的区别

[英]Difference between #ifdef __linux and #ifdef __unix in C++ header file

I've seen some boilerplate header file code for dealing with different OS's, like the following: 我已经看到了一些用于处理不同操作系统的样板头文件代码,如下所示:

#ifdef __WIN32
    //windows
#elif __linux
    //linux
#elif __unix
    //all unix not captured above
#endif

If __unix catches all unices not captured by __linux , why not just use __unix ? 如果__unix捕获了__linux未捕获的所有__linux ,为什么不使用__unix I'm assuming it's some sort of safeguard, like "if __linux isn't enough, use this". 我假设这是某种保护措施,例如“如果__linux还不够,请使用此”。

However, there has to be some reason both are used, instead of just having a catch-all with __unix (once again, this assumption may be wrong). 但是,必须使用某些原因,而不是仅使用__unix进行全面__unix (再次,这种假设可能是错误的)。

What's the deal? 这是怎么回事?

As have been stated in the comments Unix and Linux are two different operating systems and although a large amount of software is compatible they have a separate licensing structure. 如评论中所述,Unix和Linux是两种不同的操作系统,尽管兼容许多软件,但它们具有单独的许可结构。 This means that a number of tools that are available in Linux are not available in Unix and vice versa. 这意味着Linux中可用的许多工具在Unix中不可用,反之亦然。 An example of this is Unix's ZFS file system which cannot be distributed under the same license as Linux and as a result support is not included in stock Linux kernels (although it is possible to compile a custom kernel with support). 一个例子是Unix的ZFS文件系统,该文件系统不能以与Linux相同的许可证进行分发,因此,现有的Linux内核中不包括支持(尽管可以在支持的情况下编译自定义内核)。 In terms of the particular boiler plate it is likely that it is just covering all basis and could be used to take advantage of particular tools that are available on each operating system. 就特定的样板而言,它可能仅涵盖所有基础,并且可以用来利用每个操作系统上可用的特定工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM