Create "long long" type in C++

We have a database library we want to use in our embedded application but it requires 64 bit longs (long long or _int64). Our current compiler doesn't support this type and won't anytime soon. As it is a C++ compiler, is it not true that I can overload the basic arithmetic operators and create my own "longlong" type?

I'm not terribly familiar with C++ but I figure it something that can be done and maybe it's been done already.

Anyone know of any public domain code for this?

--
Allan Williams
Reply to
Al Williams
Loading thread data ...

Yes, it can be done. But it won't as efficient as it could be if it were implemented as a native type by the compiler. C/C++ is very poor at handling a carry or borrow with the same efficiency as assembler. But if your compiler supports in-line assembler, then you might be able to do it. On the other hand, if performance is not an issue, then forget about assembler and efficiency and make a C++ class to do _int64 arithmetic however you want.

-Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)

Reply to
Robert Scott

it

doesn't

You can do that, but be careful with what you want to do. If it were me, I'd resist doing a full C++ library with overloads and stuff. I'd much prefer to isolate exactly which parts of the program needed to be done in 64 bits and define functions solely for those parts which needed it.

I had to do this sort of thing where the original program (in assembler!) needed to generate Standard Deviations (which involves squaring and rooting) of values that started off as 32 bits. This was the only part of the program that needed 64 bits, so what I did was to create a "standard deviation accumulator" class in C++: it took its input (and produced its output) in the 32 bit domain, but worked internally in

64 bits.

Richard [in PE12]

Reply to
Endymion Ponsonby-Withermoor III

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.