• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 884
  • Last Modified:

Large integer support in Visual C++ 2005

Hi,

I need to migrate an application core from Visual C++ 6.0 to Visual C++ 2005. I have already replaced some of the depecated functions for their "safe" version. I also replaced some libraries for their new version (i.e change "#include <iostream.h>" for "#include <iostream>").  However the compiler gave an error with "#include <largeint.h>" i found that this library not longer exists because large integers are now natively supported so i commented out that line and changed the variable declarations from LARGE_INTEGER to the new type _LARGE_INTEGER but then i don't know what to do with the functions LargeIntegerLessThan, LargeIntegerSubtract, LargeIntegerAdd, how can i replace them?

Sample code:

   void CNTTimer::Stop()
   {
      if (fTooFast)
         return;

      if (fTimerStarted)
      {
         QueryPerformanceCounter(&liStopTime);

         int liDeltaTime;

         // See if internal hardware counter overflowed.

         if (LargeIntegerLessThan(liStopTime, liStartTime))
         {
            liDeltaTime.HighPart = 0xffffffff;
            liDeltaTime.LowPart  = 0xffffffff;
            liDeltaTime = LargeIntegerSubtract(liDeltaTime, liStartTime);
            liDeltaTime = LargeIntegerAdd     (liDeltaTime, liStopTime);
         }
         else
            liDeltaTime = LargeIntegerSubtract(liStopTime, liStartTime);

         liAccumTime   = LargeIntegerAdd(liAccumTime, liDeltaTime);
         fTimerStarted =  FALSE;
         if (liAccumTime.HighPart)
         {
            liAccumTime.HighPart = 0;
            liAccumTime.LowPart  = 0;
         }
      }  // fTimerStarted
   }  // Stop

Thanks,

Johann
0
JohannRamon
Asked:
JohannRamon
  • 2
1 Solution
 
jkrCommented:
>> i don't know what to do with the functions LargeIntegerLessThan,
>>LargeIntegerSubtract, LargeIntegerAdd, how can i replace them?

Work with the 'QuadPart' member of the LARGE_INTEGER struct, it is nothing but a plain '__int64' for which all mathematical operations are defined, e.g.

         // See if internal hardware counter overflowed.

         if (liStopTime.QuadPart <  liStartTime.QuadPart)
         {
            liDeltaTime.HighPart = 0xffffffff;
            liDeltaTime.LowPart  = 0xffffffff;
            liDeltaTime.QuadPart = liDeltaTime.QuadPart - liStartTime.QuadPart;
            liDeltaTime.QuadPart = iDeltaTime.QuadPart + liStopTime.QuadPart;
         }
         else
            liDeltaTime.QuadPart = liStopTime.QuadPart - liStartTime.QuadPart;

         liAccumTime.QuadPart   = liAccumTime.QuadPart + liDeltaTime.QuadPart;
0
 
itsmeandnobodyelseCommented:
Actually the built-in 64 bit integer is __int64 and not _LARGE_INTEGER.

The _LARGE_INTEGER is a struct (or better a union) which is typedef'd to LARGE_INTEGER. So both can be used synonymously. If you need to use a LARGE_INTEGER, e. g. as an argument, you might copy a __int64 to the QuadPart member of the LARGE_INTEGER.

The only thing missing is the largeint.h where the definitions were moved in VC8.

>>LargeIntegerSubtract, LargeIntegerAdd, how can i replace them?
replace them by operator + or operator -.

Regards, Alex

Regards, Alex
0
 
itsmeandnobodyelseCommented:
Hmmm. I was much too slow ...
0
 
JohannRamonAuthor Commented:
jkr, thanks for your prompt response. It was very fast, to the point and showed me in the code exactly what i needed to do.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now