2

What is the difference between InterlockedExchange and InterlockedExchangePointer?

Are

if( 0 != InterlockedCompareExchange( ( void** ) &_myVariable
                                   , temp
                                   , 0
                                   ) )

and

if( 0 != InterlockedCompareExchangePointer( ( void** ) &_myVariable
                                          , temp
                                          , 0
                                          ) )

equivalent?

I have to port code to VC6 which does not know of the Interlocked[...]Pointer functions.

Edit:

I know from my own experience, that VC6 is extremely buggy and that no one shall use it anymore.

However, I am not a decision-maker and an answer to the original question would be highly appreciated.

Martin85
  • 308
  • 4
  • 13
  • 4
    You have to port code … *to* VC6? Forget it. VC6 is discontinued, *extremely* buggy and dead. Do not develop new code for/with it, and migrate existing projects *away* from it – it *will* be cheaper in the long run. – Konrad Rudolph Dec 12 '12 at 10:41
  • Have you tried http://msdn.microsoft.com/en-us/library/windows/desktop/ms683590.aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/ms683609.aspx? (Also, AFAICS the first one would not compile, and the second one has a redundant cast) – R. Martinho Fernandes Dec 12 '12 at 10:44

1 Answers1

5

InterlockedCompareExchange takes a 32 bit variable.

InterlockedCompareExchangePointer takes a pointer-size variable, which is different depending on the target architecture.

If you target 32 bit and only 32 bit architectures it will be fine, however whenever you change the target architecture to 64 bit, the following will compile and behave nasty:

InterlockedCompareExchange( ( LONG volatile * ) _myPointer , 1, 0 ) );
Peter
  • 5,608
  • 1
  • 24
  • 43