Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ?  
Author Message
CPPUSer7





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

Hello All,

Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer

Thanks in Advance,
CPPUser7


Visual C++9  
 
 
nobugz





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

This code compiled and executed without problems at /W4:
int i1 = -1;
unsigned __int64 i2 = i1;
System::Int32 i3 = -1;
System::Int64 i4 = i3;



 
 
CPPUser7





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

Hello nobugz,

Thanks for your response. But I am looking for some Win API macro if exists which does this job. My requirement is to convert a long to ULONGLONG.

Any pointers will be appreciated.



 
 
nobugz





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

Same idea, compiles and executes fine at /W4:
long i1 = -1;
ULONGLONG i2 = i1;
Why do you need a macro



 
 
CPPUser7





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

The problem with this direct assignment is,

I am getting the following warning upon building
"warning C4244: '+=' : conversion from 'long' to 'ULONGLONG', possible loss of data"
I wanted a solution without any warnings.

I thought, I could zero off the High bit(which holds the sign) in the 32 bit signed integer and get an unsigned 32 bit and then assign this to 64 bit unsigned integer. Something like this

long l = 3;
ULONG ul = l & 0x7FFFFFFF;
ULONGLONG ull = ul;

But still I am not convinced as this works on application running on 32 bit system(which I am currently working on) but not sure if the same code will work for application running on 64 bit system. So, looking if Win API provides any such macro to do the job.


 
 
Brian Kramer





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

ULONGLONG should be a typedef:

typedef unsigned __int64 ULONGLONG;

Try using "right click: Go to definition" on ULONGLONG to see if it is any different.


 
 
CPPUser7





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

You are correct Brian, ULONGLONG is a typedef. can you please throw some light on this issue.

 
 
Brian Kramer





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

Is it the same definition as the one I've shown Can you give a complete repro (in as few lines as possible) that includes the #included files Also, which version of Visual C++ are you using
 
 
CPPUser7





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

Go to definition takes me to 3 different symbols to resolve ambiguity

1. C:\program files\microsoft visual studio.net\VC7\platformsdk\include\oledb.h
Here ULONGLONG is defined as
typedef MIDL_uhyper ULONGLONG;

and in rpcndr.h MIDL_uhyper is defined as
#define MIDL_uhyper unsigned __int64

2. C:\program files\microsoft visual studio.net\VC7\platformsdk\include\winnt.h
typedef unsigned __int64 ULONGLONG;

3. C:\program files\microsoft visual studio.net\VC7\platformsdk\include\wtypes.h
typedef unsigned __int64 ULONGLONG;

I am running Microsoft Visual C++ .NET on Microsoft Development Environment 2002 Version 7.0.9955 and
Microsoft .NET Framework 1.0 version 1.0.3705

Please let me know if you needed more information. Thanks for your time.


 
 
CPPUser7





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

Coming to my problem. I have a function which currently returns a long and I have to change this function to return unsigned 64 bit integer so I have chosen ULONGLONG.



 
 
Brian Kramer





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

To get to the bottom of this, it would help to be be compiling the same code with the same version of Visual Studio.

Try this (I have VS 2005):

#include <windows.h>

int main()
{
long i1 = -1;
ULONGLONG i2 = i1;
printf(
"%I64x\n",i2);
}


 
 
Nishant Sivakumar





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

It doesn't matter that it's defined in 3 header files (all of which are probably included directly or indirectly) as all three define it the same way. So I don't see how you get a warning.

 
 
Nishant Sivakumar





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

I just compiled that with VC 2003 and didn't get any warning. Try compiling a minimal cpp that will reproduce the warning, and copy/paste the full listing here so the rest of us can try it out too.

 
 
nobugz





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

OK, with what we know sofar, I tried this:
long func() {
return -1;
}

int _tmain(int argc, _TCHAR* argv[])
{
ULONGLONG i = 0;
i += func();
}

Still no warning. It would, like, really, really help if we could see your code. I mean, really...



 
 
CPPUser7





PostPosted: Visual C++ Language, Is there a macro which converts a 32 bit signed integer to 64 bit unsigned integer ? Top

Sorry for the late response. All your answers are correct, you don't get any warning while converting a 32 bit signed to 64 bit unsigned. My problem was with some other part of the code throwing warnings.

Thanks a lot for you responses