Opened 15 years ago

Closed 15 years ago

#1069 closed Bugs (invalid)

_InterlockedExchange, _InterlockedExchangeAdd have wrong signature

Reported by: Braden McDaniel <braden@…> Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.34.0 Severity: Problem
Keywords: Cc:

Description

Microsoft describes the signature of _InterlockedExchange as

extern "C" LONG  __cdecl _InterlockedExchange(LPLONG volatile Target, LONG Value);

See http://msdn2.microsoft.com/en-us/library/f24ya7ct(VS.71).aspx

In boost/detail/intrinsic.hpp, this function gets declared as

extern "C" __declspec(dllimport) long __stdcall InterlockedExchange( long volatile *, long );

The problem is that LPLONG volatile is equivalent to long * volatile, not long volatile *. This results in compilation failures in the presence of a correct declaration of this function; i.e., the compiler complains that you cannot overload C functions.

Attachments (1)

interlocked.patch (819 bytes ) - added by Braden McDaniel <braden@…> 15 years ago.
Patch

Download all attachments as: .zip

Change History (6)

by Braden McDaniel <braden@…>, 15 years ago

Attachment: interlocked.patch added

Patch

in reply to:  description comment:1 by Braden McDaniel <braden@…>, 15 years ago

As suggested in the summary, the declaration of _InterlockedExchangeAdd has the same problem.

comment:2 by Peter Dimov, 15 years ago

Component: Building Boostsmart_ptr
Owner: set to Peter Dimov
Severity: ShowstopperProblem
Status: newassigned

On which compiler are you seeing this behavior? The actual declaration in <windows.h> is as follows:

WINBASEAPI LONG WINAPI InterlockedExchange(

IN OUT LONG volatile *Target, IN LONG Value );

with the volatile correctly applied to *Target.

comment:3 by braden@…, 15 years ago

The compiler is Visual C++ 7.1. The problem arises because code in another dependency has declared the function the way the Microsoft documentation recommends. Since the signatures are different, the compiler complains that an extern "C" function has been overloaded.

comment:4 by Peter Dimov, 15 years ago

The Microsoft documentation is wrong in this case. If we change the code to be wrong as well, the signatures will no longer match the ones in <windows.h>. The documentation for InterlockedExchange

http://msdn2.microsoft.com/en-us/library/ms683590.aspx

correctly specifies the signature as taking LONG volatile*. BTW, you can't declare a function parameter as long * volatile, the volatile is ignored.

comment:5 by Peter Dimov, 15 years ago

Resolution: invalid
Status: assignedclosed
Note: See TracTickets for help on using tickets.