I am reusing some C / C ++ source files from the autotools project in a CMake project, and I see a lot of source files cluttered with lines like:
#ifdef HAVE_UNISTD_H #include <unistd.h> // for getpid() #endif
I would understand the purpose of this construct if it getpid()was optional, and its call was surrounded by equivalent directives HAVE_UNISTD_H. However, without the HAVE_UNISTD_Hsource file is not compiled, complaining that it is getpid()not defined. This seems a lot more mysterious than the compiler letting me know that it was unistd.hnot found.
getpid()
HAVE_UNISTD_H
unistd.h
Of course, this is just an example. Other popular macros include HAVE_STDINT_H, HAVE_INTTYPES_Hetc., the presence of which is required to compile the source file.
HAVE_STDINT_H
HAVE_INTTYPES_H
Why are the guards HAVE_*turned on at all? I feel that they only bring flaws:
HAVE_*
#include
#ifdef
HAVE_xxx_h - POSIX . 90- , getpid(), unistd.h - , , ( -) - , K & R C89 C.
HAVE_xxx_h
. , , time.h, , sys/time.h, , , , , ! , , , Autoconf, - .
time.h
sys/time.h
-POSIX-, . posix , , gnulib.
HAVE_ * ? , :...
. , , , .
1:
#ifdef HAVE_UNISTD_H #include <unistd.h> // for getpid() #endif #ifdef HAVE_WINDoWS_H #include <windows.h> // for GetProcessId() #endif
1 , Windows getpid().
Source: https://habr.com/ru/post/1681058/More articles:Visual Studio Code Change Format (React-JSX) - reactjsKarma test task fails after grunt-ts compiles typescript in js - gruntjsHow to check in which places our local storage data is stored in our system? - angularjsFor each char string, the string displays the wrong result - c ++Группировка отчета по охвату кода istanbul по папке - javascriptOpenCL backend in Java Encog 3 - javaTravis-CI: Knitr not found in loadVignetteBuilder - rUnable to instantiate class ViewModel - androidMdBootstrap with Angular - angularНечетное поведение автоматического прокрутки/перехода в Chrome (iOS) при переходе на следующую страницу - htmlAll Articles