libpkgconf.h introduces min() and max() macros on Windows #137

Closed
opened 2017-09-14 08:09:58 +00:00 by karen-arutyunov · 1 comment
karen-arutyunov commented 2017-09-14 08:09:58 +00:00 (Migrated from github.com)

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.

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<int>::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.
karen-arutyunov commented 2017-09-15 11:32:48 +00:00 (Migrated from github.com)

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)?

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)?
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ariadne/pkgconf#137
There is no content yet.