long long implementation in 32 bit machine

The equivalent in C++ is long long as well. It’s not required by the standard, but most compilers support it because it’s so usefull.

How is it implemented? Most computer architectures already have built-in support for multi-word additions and subtractions. They don’t do 64 bit addititions directly but use the carry flag and a special add-instruction to build a 64 bit add from two 32 bit adds.

The same extension exists for subtraction as well (the carry is called borrow in these cases).

Longword multiplications and divisions can be built from smaller multiplications without the help of carry-flags. Sometimes simply doing the operations bit by bit is faster though.

There are architectures that don’t have any flags at all (some DSP chips and simple micros). On these architectures the overflow has to be detected with logic operations. Multi-word arithmetic tend to be slow on these machines.

Leave a Comment