What is the purpose of the features.h header?

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

Does it determine the initial functions supported by the system? Or does it define some additional things that need to be defined depending on other definitions?

+12
source share
4 answers

The features.h header file provides various macro definitions that indicate standard compliance with other header files, i.e. which functions (hence the name) should be enabled or disabled depending on which standard the user wants to use.

Most C / C ++ compilers have command line options for standard compliance. Take GCC as an example: when you pass the -std=gnu9x , you request a GNU dialect of the C99 standard. The features.h header ensures that all other headers that include it will include those or other features that are necessary to support this particular dialect. This is achieved using #define -ing or #undef with some "intermediate" macros.

As a bonus, features.h also provides macros with glibc version information, as well as various other bits and beans.

+6
source

In general, if you need to use any variables or functions defined in the header file, you need to include it in your program. This rule holds true for features.h . The features.h url is below:

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

+1
source

From features.h File Link

Determines whether to include options for the algorithm. Smaller options reduce executable file size and compilation time. This file is a parallel GNU extension for the C ++ standard library.

Thus, this file will contain some algorithm indicated on the link page.

+1
source

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

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

One of the interesting things he defines is 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, outputs:

 __GLIBC__ 2 __GLIBC_MINOR__ 23 

See also: Check the glibc version for a specific gcc compiler

Also, this header seems to be included in most / all glibc headers, which may allow you to check if glibc is used: how to determine if glibc is used, but TODO I could not find the documentation for this.

+1
source

Source: https://habr.com/ru/post/985173/


All Articles