Opened 13 years ago

Closed 13 years ago

#3901 closed Bugs (fixed)

ASIO and macro min and max on Windows

Reported by: habdank@… Owned by: chris_kohlhoff
Milestone: Boost 1.43.0 Component: asio
Version: Boost 1.40.0 Severity: Problem
Keywords: Cc:

Description

Dears,

There is little problem with ASIO on windows. ASIO is using windows.h header. That header defines "min" and "max" macros.

So immediately asio is conflicting with standard <limits> and <algorithm> headers.

The error generated by the compilers is higlhy not readable. Also regular user of the asio does not know that windows.h is included and pollute standard C++ code with mentioned macros.

Try to use ::std::numeric_limits<int>::min() ::std::numeric_limits<int>::max() as well as ::std::min() together with ASIO.

For users would be perfect if you could simply put #undef min and #undef max just after inclusion of any windows.h file.

The problem is more complicated because the same code is working on Linux, so from C++ portable code it is uncomfortable to have such a intrusions.

Best regards, Seweryn Habdank-Wojewodzki

Change History (5)

comment:1 by jan.boehme@…, 13 years ago

This is an issue asio shouldn't care about. Just <define>NOMINMAX when building on this platform.

comment:2 by habdank@…, 13 years ago

Hi,

To be honest I disagree that it is not a matter of ASIO.

This is a matter of good encapsulation. Inclusion of the windows.h is a private matter of ASIO. Even more if ASIO would use PIMPL idiom maybe no one would be affected by that macros.

Also consider that if ASIO will stop using windows.h for some reasons, any code will be still affected - then by having useless undefs or NOMINMAX build flag.

As I told that macros are conflicting with standard C++.

Off course I could build my software with NOMINMAX flag or do the #undef on my own :-).

Best regards, Seweryn Habdank-Wojewodzki.

comment:3 by chris_kohlhoff, 13 years ago

Fixed on trunk in changeset [60681].

in reply to:  3 comment:4 by anonymous, 13 years ago

Replying to chris_kohlhoff:

Fixed on trunk in changeset [60681].

Thanks!

comment:5 by chris_kohlhoff, 13 years ago

Resolution: fixed
Status: newclosed

(In [60741]) Merge from trunk.

........

r60681 | chris_kohlhoff | 2010-03-18 12:32:34 +1100 (Thu, 18 Mar 2010) | 3 lines

Define NOMINMAX for all Windows compilers, not just Cygwin. Users can define BOOST_ASIO_NO_NOMINMAX to suppress this definition. Fixes #3901.

........

r60687 | chris_kohlhoff | 2010-03-18 17:23:38 +1100 (Thu, 18 Mar 2010) | 4 lines

Use a bitmask type for the resolver flags, as per the TR2 proposal. This will prevent implicit conversion from int to flags, allowing the compiler to catch cases where users incorrectly pass a numeric port number as the service name.

........

r60689 | chris_kohlhoff | 2010-03-18 22:08:19 +1100 (Thu, 18 Mar 2010) | 2 lines

Fix bug where 0-byte reads were incorrectly passing an eof error_code to the handler. Fixes #4023.

........

r60705 | chris_kohlhoff | 2010-03-20 00:08:04 +1100 (Sat, 20 Mar 2010) | 3 lines

Fix epoll_reactor bug where cancelled operations would complete with a "success" error_code.

........

r60717 | chris_kohlhoff | 2010-03-20 10:23:28 +1100 (Sat, 20 Mar 2010) | 2 lines

More extensive read and write tests.

........

r60722 | chris_kohlhoff | 2010-03-20 10:57:50 +1100 (Sat, 20 Mar 2010) | 2 lines

WinCE doesn't provide InitializeCriticalSectionAndSpinCount.

........

r60723 | chris_kohlhoff | 2010-03-20 10:58:48 +1100 (Sat, 20 Mar 2010) | 2 lines

Fix cancellation.

........

r60725 | chris_kohlhoff | 2010-03-20 10:59:48 +1100 (Sat, 20 Mar 2010) | 3 lines

Use cancel() to avoid Windows behaviour where a connection is reset if the socket is closed while there is a pending read operation.

........

Note: See TracTickets for help on using tickets.