What is the purpose of features.h header?

前端 未结 4 1490
北海茫月
北海茫月 2020-12-29 08:15

What is the purpose of the features.h header? Why and when can it be used in my code?

Does it define source features supported by the system? Or does i

相关标签:
4条回答
  • 2020-12-29 08:48

    From features.h File Reference

    Defines on whether to include algorithm variants. Less variants reduce executable size and compile time. This file is a GNU parallel extension to the Standard C++ Library.

    So this file will include some algorithm listed in the reference page.

    0 讨论(0)
  • 2020-12-29 08:54

    I have grepped POSIX 7 as explained at: https://unix.stackexchange.com/questions/340285/install-the-latest-posix-man-pages/483198#483198 and there are no hits for features.h, so it must be a glibc extension only.

    In glibc 2.28, it is present at include/features.h.

    One of the interesting things that it defines are version macros:

    #include <stdio.h>
    #include <features.h>
    
    int main(void) {
      printf("__GLIBC__       %u\n", __GLIBC__);
      printf("__GLIBC_MINOR__ %u\n", __GLIBC_MINOR__);
      return 0;
    }
    

    Ubuntu 16.04, which has glibc 2.23, this outputs:

    __GLIBC__       2
    __GLIBC_MINOR__ 23
    

    See also: Check glibc version for a particular gcc compiler

    Also, this header seems to get included in most / all glibc headers, which might allow you to check if glibc is being used: How to tell if glibc is used but TODO I couldn't find a documentation for that.

    0 讨论(0)
  • 2020-12-29 09:00

    In general if you need to use any of the variables or functions defined in a header file, you need to include it in your program. This rule is valid for features.h also. You can see a URL for features.h for your reference below:

    http://repo-genesis3.cbi.utsa.edu/crossref/heccer/usr/include/features.h.html

    0 讨论(0)
  • 2020-12-29 09:04

    The features.h header file provides various macro definitions that indicate standard conformance to other header files, i.e. which features (hence the name) should be turned on or off depending on which standard the user wishes to use.

    Most C/C++ compilers have command line options to handle standards conformance. Let's take GCC as an example: when you pass the -std=gnu9x option, you ask for the GNU dialect of the C99 standard. The features.h header makes sure that all other headers that include it will turn exactly those features on or off that are needed to support this particular dialect. This is achieved by #define -ing or #undef - ing some "intermediate" macros.

    As a bonus, features.h also provides the glibc version information macros as well, and various other bits & bobs.

    0 讨论(0)
提交回复
热议问题