When defining macros that headers rely on, such as _FILE_OFFSET_BITS
, FUSE_USE_VERSION
, _GNU_SOURCE
among others, where is the best place to put them?
Some possibilities I've considered include
CPPFLAGS
level via the compiler? (such as -D_FILE_OFFSET_BITS=64
) for the:
A note: Justification by applicability to make, autotools, and other build systems is a factor in my decision.
Avoid defining macros, especially in headers; prefer inline functions, enums, and const variables.
Because a header file might potentially be included by multiple files, it cannot contain definitions that might produce multiple definitions of the same name. The following are not allowed, or are considered very bad practice: built-in type definitions at namespace or global scope. non-inline function definitions.
stddef. h is a header file in the standard library of the C programming language that defines the macros NULL and offsetof as well as the types ptrdiff_t, wchar_t, and size_t.
The Windows Driver Kit (WDK) contains all the header files (. h files) that you need to build kernel-mode and user-mode drivers. Header files are in the Include folder in your WDK installation folder.
If the macros affect system headers, they probably ought to go somewhere where they affect every source file that includes those system headers (which includes those that include them indirectly). The most logical place would therefore be on the command line, assuming your build system allows you to set e.g. CPPFLAGS to affect the compilation of every file.
If you use precompiled headers, and have a precompiled header that must therefore be included first in every source file (e.g. stdafx.h for MSVC projects) then you could put them in there too.
For macros that affect self-contained libraries (whether third-party or written by you), I would create a wrapper header that defines the macros and then includes the library header. All uses of the library from your project should then include your wrapper header rather than including the library header directly. This avoids defining macros unnecessarily, and makes it clear that they relate to that library. If there are dependencies between libraries then you might want to make the macros global (in the build system or precompiled header) just to be on the safe side.
Well, it depends.
Most, I'd define via the command line - in a Makefile or whatever build system you use.
As for _FILE_OFFSET_BITS
I really wouldn't define it explicitly, but rather use getconf LFS_CFLAGS
and getconf LFS_LDFLAGS
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With