ULongLong2LongLong

© 2022 John Abbott, Anna M. Bigatti
GNU Free Documentation License, Version 1.2



CoCoALib Documentation Index

User documentation

Generalities

The function ULongLong2LongLong converts an unsigned long long value into a signed long long, effectively inverting the standard C++ cast from signed long long to unsigned long long. Note that applying a static_cast might not produce the desired result -- officially the outcome is "implementation defined".

Maintainer Documentation

There are three different implementations. The choice between them is determined by the value of the CPP symbol COCOA_ULONGLONG2LONGLONG; a suitable value for this symbol is found by a script called by the configure script. That script selects the simplest implementation which works (on certain test cases). Note that C++ explicitly forbids the use of reinterpret_cast on built-in integral types, but the trick of applying to a reference seems to work (it was suggested to me by Chris Jefferson).

An earlier version of this function was in utils.H, but it turned out to be simpler to place it by itself in a separate header file (because the ULongLong2LongLong.H includes no further headers, so the test compilations made by the script cpp-flags-ulonglong2longlong.sh are simpler and safer).

Everything is in the header file; there is no ULongLong2LongLong.C file.

Bugs, shortcomings and other ideas

The fully portable definition is long and slow -- this seems to be a problem of the C++ standard.

Main changes

2022