Ask Your Question
0

What is the correct way to utilize __has_include?

asked 2021-06-01 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-04-22 16:00:00 +0000

woof gravatar image

_hasinclude is a preprocessor macro that allows you to check whether a header file is available before including it in your code. It is useful when writing cross-platform code that might require different header files on different systems.

The correct way to utilize _hasinclude is to use it in a conditional statement, like this:

#if __has_include(<header_file>)
    // header file is available
    #include <header_file>
#else
    // header file is not available
#endif

Replace <header_file> with the name of the header file you want to check for. The code inside the #if block will only be compiled if the header file is available, otherwise the code inside the #else block will be compiled instead.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-01 11:00:00 +0000

Seen: 16 times

Last updated: Apr 22 '21