libpkgconf.h introduces min() and max() macros on Windows #137
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
On Windows including libpkgconf.h into the client code introduces min() and max() macros (defined in windows.h) which clash with some C++functions.
For example the following code:
#include <limits>
#include <libpkgconf/libpkgconf.h>
static int a (std::numeric_limits::max ());
results in the warning if is compiled with MSVC:
warning C4003: not enough actual parameters for macro 'max'
While the issue is workarounded by adding '# define NOMINMAX' prior to including windows.h in stdinc.h, the code inside '#ifdef _WIN32' clause will stay broken in a sense. Imagine that someone have already defined WIN32_LEAN_AND_MEAN and NOMINMAX in his code prior to including libpkgconf.h. In this case "macro redefinition" warnings will be issued.
Generally it is not clear at all why the most content of stdinc.h is exposed to the client code. Most of it just the library implementation details. Why not to include it into the library C files directly, removing its include from libpkgconf.h and instead including only those standard headers that are required for the library interface, say:
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
Think that could help to avoid the reported and some other, yet undiscovered, issues.
Just to let you know, we (at Code Synthesis) have packaged libpkgconf library for the build2 package manager (bpkg):
https://stage.build2.org/libpkgconf
Now it is automatically built and smoke-tested with a number of OS/compiler combinations.
Btw is there some email where pkgconf project feedback or questions can be directed (mailing list or smth)?