Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_Decimal64 does not have a type in C++

I am mixing C with C++ source code using GNU. _Decimal64 is recognised fine in C, but not in C++. C++ complains error: '_Decimal64' does not name a type.

Is there any way I can fix this? Should I consider it a compiler bug?

Update 20-Mar-2017 18:19:

None of the answers meet my requirements so far. I don't want to use the decimal64 C++ class, I want to use the _Decimal64 C type. My project is mostly written in C, but I want to slowly introduce C++ code. Here, for example, is part of cell.h:

union vals
  {
          num c_n;
          //double c_d;
          char *c_s;
          long c_l;
          int c_i;
          struct rng c_r;
  };

It is made use of in cells.c, which of course is C code. num is defined in numeric.h:

#pragma once

#ifdef __cplusplus
#define USE_DECIMAL 0
#else
#define USE_DECIMAL 1
#endif

#if USE_DECIMAL
typedef _Decimal64 num;
#define NUM_HUNDREDTH 0.01DL
#define NUM_TEN 10.0DL
#else
typedef double num;
#define NUM_HUNDREDTH 0.01
#define NUM_TEN 10.0
#endif

Notice that I have use typedef double num to get a compile on the C++ side. C++ doesn't actually num type, but it is inevitably included because it needs some of the functionality in the C files.

It's faking it, of course.num isn't a double, it's really a _Decimal64. I'm asking how I can get around this kludge.

like image 660
blippy Avatar asked Sep 20 '25 04:09

blippy


2 Answers

For C++ "decimal64"

use std::decimal::decimal64

the standard says:

https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.6/a00454.html

like image 148
Pavan Chandaka Avatar answered Sep 22 '25 17:09

Pavan Chandaka


_Decimal64 is neither standard C++ nor standard C. It is simply proposed in the TR 24732 document.

Ok, gcc supports it at least when compiling C source. The C++ counterpart seems to be TR 24733. It defines a std::decimal::decimal64 class.

Those definition are likely to be compatible, because I cannot imagine GCC fellows to build 2 different implementation of the IEE754 decimal floating points, but according to that other SO post gcc support is still incomplete (at the time of the post, that is 2012).

You must dig in gcc documentation to find more because it is currently implemented as a gcc extension.

like image 27
Serge Ballesta Avatar answered Sep 22 '25 17:09

Serge Ballesta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!