Integer and Float type definitions with respect to bits number

Dears All ,

It seems that , in Clang , there is no a type system like the following :

Integer_8_Bits_Positive
Integer_8_Bits_Signed

Integer_16_Bits_Positive
Integer_16_Bits_Signed

Integer_32_Bits_Positive
Integer_32_Bits_Signed

Integer_64_Bits_Positive
Integer_64_Bits_Signed

Float_48_Bits
Float_64_Bits
Float_80_Bits
Float_128_Bits

The following are defined with respect to above types AND Operating System ,
Processor requirements to enable to compile the SAME sources for different
environments :

Integer_Default_Bits_Positive
Integer_Default_Bits_Signed

Float_Default_Bits

The existing definitions ( long , long long , etc. ) are very ambiguous and
depending on the platform without clearly showing exact bits number .

Is there a possibility to include definitions such as above into Clang
or , if there exist such a definition , what is its name ?

Thank you very much .

Mehmet Erol Sanliturk

Have a look at <stdint.h> for integer types. This should be a part of your standard library for any C99-compliant compilers. For Windows, they're included in MSVC2012 onwards.

float and double are always defined to be 32- and 64-bit, respectively. Beyond that you're in a platform-specific extension area. See, for example: http://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html

  - ½

Have a look at <stdint.h> for integer types. This should be a part of
your standard library for any C99-compliant compilers. For Windows, they're
included in MSVC2012 onwards.

float and double are always defined to be 32- and 64-bit, respectively.
Beyond that you're in a platform-specific extension area. See, for example:
http://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html

- ½

In Linux :
/usr/lib/clang/3.3/include/stdint.h

contains these definitions .

In Clang , there is no

quadmath.h .

When Clang encounters

#include <quadmath.h>

it is using gcc source , but it is giving errors .

( In /usr/lib/gcc/x86_86-redhat-linux/4.7.2/include/quadmath.h ,
there are __float128 and __complex128 )

I could not find any __float64 , __float80 , __complex64 , __complex80 .

Thank you very much .

Dears All ,

It seems that , in Clang , there is no a type system like the following :

Integer_8_Bits_Positive
Integer_8_Bits_Signed

Integer_16_Bits_Positive
Integer_16_Bits_Signed

Integer_32_Bits_Positive
Integer_32_Bits_Signed

Integer_64_Bits_Positive
Integer_64_Bits_Signed

Float_48_Bits
Float_64_Bits
Float_80_Bits
Float_128_Bits

The following are defined with respect to above types AND Operating System ,
Processor requirements to enable to compile the SAME sources for different
environments :

Integer_Default_Bits_Positive
Integer_Default_Bits_Signed

Float_Default_Bits

The existing definitions ( long , long long , etc. ) are very ambiguous and
depending on the platform without clearly showing exact bits number .

Is there a possibility to include definitions such as above into Clang
or , if there exist such a definition , what is its name ?

There is a proposal to add optional floating-point definitions (adding to existing integer like int32_t) to the next version of the C and C++ standards:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3626.pdf

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1703.pdf

This will at least standardise the names of specified-width typedefs.

Of course some typedefs may require compiler support,

or a multiprecision library like

http://www.boost.org/doc/libs/1_54_0/libs/multiprecision/doc/html/index.html

which now also has experimental cpp_bin_float types

https://svn.boost.org/svn/boost/sandbox/multiprecision.cpp_bin_float/

that can emulate various binary layouts.

HTH

Paul

Having standard names are important to prevent ambiguity in programs .
This is especially important for multiple platform programming ( ( 32-bits
, 64-bits ) x ( operating systems , processors ) x different compilers )
and maintaining programs over time : Many years ago , "int" was two-bytes ,
but now it is very rare , and conversion of such programs are very
difficult .

Another problem is occurring in file records : If variable types are not
specified by bit-sizes , to use the same file in a file server by different
bit-size operating systems are becoming a very difficult or error prone
task .

To solve such problems , it is important to have variable kinds specified
by bit-numbers .

To supply such definitions in compiler libraries is a more lasting and
error-free approach for the users . Over time , missing parts may be
completed with new bit-sized type definitions instead of definitions like (
long .. , long long ... , long long long ... ) .

Thank you very much .

Mehmet Erol Sanliturk

Dears All ,

It seems that , in Clang , there is no a type system like the following :

The <stdint.h> header provides typedefs for {,u}int{8,16,32,64}_t definitions, and I would heartily recommend that anyone using C or C++ use these typedefs instead of unadulterated char/short/int/long/long long. However, the compiler can only provide the ambiguously-sized int et al (and refer to them as such internally), since to change that would be to potentially break the ABI of existing code.

Float_48_Bits
Float_64_Bits
Float_80_Bits
Float_128_Bits

The situation for floating point is not as clear cut. While there is a rough consensus that float and double refer to what IEEE 754 calls binary32 and binary64, the long double can in practice mean either x86's 80-bit precision format, IEEE's binary128, or the PPC double-double format. Some of these formats don't cleanly map on to the IEEE 754 hierarchy of floating point (which is why LLVM specifies floating point types not as a generic fN but as an enumerated, closed set of possible values).