简体   繁体   中英

how to try and catch for preprocessor directives like “#include”

is there a method to try and catch for an #include directive since #include is processor directives and try catch method is done during compilation it wont work is there any workaround for it? I need to check if a file can be included else include another file.

__has_include function along with using #if and #elif would do that.

#if defined __has_include
#  if __has_include (<stdatomic.h>)
#    include <stdatomic.h>
#  endif
#endif

Source: https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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