> This page http://msdn2.microsoft.com/en-gb/library/0wf2yk2k(VS.80).aspx
> states that both int & long map to Int32.
That's correct, but it just means that long and int are both 32-bit
signed integers under Win32 and Win64, and they're both compatible with
System::Int32. But that doesn't mean logn and int are the same exact
type. long is not simply a typedef for int. Even in native code, they're
not interchangeable types:
void f(int& value);
void test()
{
long value;
f(value); // error or warning message
}
My C++ reports an error "cannot convert parameter 1 from 'long' to
'int&'. My Borland compiler remports a warning and creates a temporary
object, whose value gets discarded after the function call.
> void fNativeArg(long *pVar /* int *pVar */)
> {
> fUniversalArg((Int32)*pVar);
Here the compiler creates a silent temporary object. fNativeArg modifies
your temporary, which gets discarded right away. Your code is
essentially equivalent with this:
void fNativeArg(long *pVar /* int *pVar */)
{
Int32 value = *pVar;
fUniversalArg(value);
}
Note how pVar will never get updated.
What you want is this:
void fNativeArg(long *pVar /* int *pVar */)
{
fUniversalArg((Int32%)*pVar);
}
After adding the % symbol, your program will print 32.
Tom
Rob - 27 Jan 2007 10:43 GMT
> But that doesn't mean logn and int are the same exact
> type. long is not simply a typedef for int. Even in native code, they're
> not interchangeable types:
Yes, I understood that...
> Here the compiler creates a silent temporary object. fNativeArg modifies
> your temporary, which gets discarded right away. Your code is
> essentially equivalent with this:
... but I hadn't thought through to what the compiler was generating.
> What you want is this:
>
[quoted text clipped - 3 lines]
>
> }After adding the % symbol, your program will print 32.
Thanks! I knew I was probably doing something daft.
Cheers
Rob