Create "long long" type in C++

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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

Re: Create "long long" type in C++
On Thu, 16 Sep 2004 18:56:40 GMT, "Al Williams"

Quoted text here. Click to load it

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.)

Re: Create "long long" type in C++
Quoted text here. Click to load it

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
to isolate exactly which parts of the program needed to be done in 64 bits
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]

Site Timeline