7

I have come across some code that basically is:

double x = 0.0d;

The d suggests to me that this is a suffix for doubles, but the documentation for floating point literals does not have it, and I cannot find any mention in the GNU g++ documentation. The compiler doesn't throw out any warnings either with -Wall.


I've made a small sample on GodBolt which answers my question with -Wpedantic, but I'd still like to see the documentation for this issue.

* Note that a similar question for Java exists.

Ken Y-N
  • 14,644
  • 21
  • 71
  • 114
  • 3
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84717 – cpplearner Nov 05 '19 at 08:19
  • @cpplearner Interesting - according to [this comment](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39027#c5) it may have been fixed in gcc 4.5.0, but it's still in my g++ 5.4.0 – Ken Y-N Nov 05 '19 at 08:25
  • 1
    Searching for the word "suffix" (full word) in [the manual](https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc.pdf) returned no relevant result. – L. F. Nov 05 '19 at 08:27
  • Yes, it is a gcc extension (to both C and C++). Historically some other programming languages use `E` and `D` interchangeably, and `E` is used for single precision (aka `float` in C++) output and `D` for double precision (aka `double` in C++) output. Algol (a language that was an ancestor of quite a few more modern languages, including C, Pascal, Fortran and others) also had a really funky floating point notation which used a subscripted "10" as an alternative to `E` or `D` – Peter Nov 05 '19 at 08:28

1 Answers1

4

This is specified in ISO/IEC TR 24732 a.k.a. WG14 N1312 technical report "Extension for the programming language C to support decimal floating-point arithmetic".

It defines d as a suffix for plain double type, and several other suffixes for decimal floating point types.

See it here (PDF).

gcc documentation mentions all these other suffixes, but not d. It is an omission.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243