git: 450f3e55bdad - stable/13 - Work around bogus old gcc "initializer element is not constant" error

Mark Millard marklmi at yahoo.com
Sat Jun 26 04:11:38 UTC 2021


Dimitry Andric dim at FreeBSD.org wrote on
Fri Jun 25 18:46:00 UTC 2021 :

. . .
>    In file included from /workspace/src/lib/msun/src/s_llround.c:11:0:
>     /workspace/src/lib/msun/src/s_lround.c:54:31: error: initializer element is not constant
>      static const type dtype_min = type_min - 0.5;
>                                    ^~~~~~~~
>     /workspace/src/lib/msun/src/s_lround.c:55:31: error: initializer element is not constant
>      static const type dtype_max = type_max + 0.5;
>                                    ^~~~~~~~
>     
>     Since 'type_min' and 'type_max' are constants declared just above these
>     lines this error is nonsensical, but older gcc's are not smart enough.
. . .

Well, in C "const" historically means closer to "read-only" than
to is-a-constant-expression in the language, unfortunately. Part
of this is the conversion away from being an lvalue (so: where
an lvalue is not required) loses the const qualification as part
of the conversion.

As:

https://en.cppreference.com/w/cpp/language/constexpr

words it in the notes:

QUOTE
C adopted the const qualifier from C++, but unlike in C++,
expressions of const-qualified type in C are not constant
expressions; they may not be used as case labels or to
initialize static and thread storage duration objects,
enumerators, or bit field sizes. When they are used as
array sizes, the resulting arrays are VLAs.
END QUOTE

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)



More information about the dev-commits-src-branches mailing list