Skip to content

Does not compile on MSVC — <unistd.h>, global min/max, and _STRING_ macro #32

Description

@binaryduke

Nodepp does not compile under MSVC (Visual Studio 2022, C++20, Windows x64). Three separate issues, each independent of the others. Happy to send a PR for all three if you'd like them.

1. include/nodepp/import.h includes <unistd.h> unconditionally.

<unistd.h> is POSIX-only and does not exist on MSVC, so the very first include fails. Guarding it is enough:

#ifndef _WIN32
#include <unistd.h>
#endif

2. include/nodepp/macros.h defines min, max and clamp as templates at global scope.

On Windows these collide with the min/max macros from <windows.h> (pulled in transitively by the Winsock headers the library itself needs), and they also conflict with std::min/std::max under ADL. Wrapping them in the nodepp namespace resolves it without changing behaviour for existing users:

namespace nodepp {
    template< class T > T   min( const T& a, const T& b ){ return a < b ? a : b; }
    template< class T > T   max( const T& a, const T& b ){ return a > b ? a : b; }
    template< class T > T clamp( const T& v, const T& lo, const T& hi ){ return max( lo, min( hi, v ) ); }
}

3. _STRING_ is too generic a macro name and collides on Windows.

Renaming it avoids the collision:

#define NODEPP_STRINGIFY(...) #__VA_ARGS__
#define _JSON_(...) json::parse(NODEPP_STRINGIFY(__VA_ARGS__))

Also worth flagging: _FUNC_ is defined as __PRETTY_FUNCTION__, which MSVC does not provide (__FUNCSIG__ is the equivalent).

Tested against V1.4.0 and the current main (V1.5.0) — both fail identically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions