From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/language%2Fconstexpr.html | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 devdocs/c/language%2Fconstexpr.html (limited to 'devdocs/c/language%2Fconstexpr.html') diff --git a/devdocs/c/language%2Fconstexpr.html b/devdocs/c/language%2Fconstexpr.html new file mode 100644 index 00000000..5cffe330 --- /dev/null +++ b/devdocs/c/language%2Fconstexpr.html @@ -0,0 +1,33 @@ +

constexpr specifier (since C23) +

A scalar object declared with the constexpr storage-class specifier is a constant. It must be fully and explicitly initialized according to the static initialization rules. It still has linkage appropriate to its declaration and it exist at runtime to have its address taken; it simply cannot be modified at runtime in any way, i.e. the compiler can use its knowledge of the object’s fixed value in any other constant expression.

+

Additionally, the constant expression that is used for the initializer of such a constant is checked at compile time.

+

An initializer of floating-point type must be evaluated with the translation-time floating-point environment.

+

There are some restrictions on the type of an object that can be declared with constexpr. Namely, the following constructs are not allowed to be constexpr:

+

Keywords

constexpr

+

Notes

Example

#include <fenv.h>
+#include <stdio.h>
+ 
+int main(void)
+{
+    constexpr float f = 23.0f;
+    constexpr float g = 33.0f;
+    fesetround(FE_TOWARDZERO);
+    constexpr float h = f / g; // is not affected by fesetround() above
+    printf("%f\n", h);
+}

Output:

+
0.696969

References

See also

+
C++ documentation for constexpr type specifier
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/language/constexpr +

+
-- cgit v1.2.3