Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a constexpr in new standard C11 (not C++11) or planned in the future?

Tags:

c

c11

In the new language standard C++11 is present the keyword constexpr.

Is there a constexpr in new standard C11 (not C++11) or planned in the future?

like image 883
Alex Avatar asked Aug 03 '13 11:08

Alex


People also ask

Is constexpr always const?

A constexpr variable must be initialized at compile time. All constexpr variables are const . A variable can be declared with constexpr , when it has a literal type and is initialized. If the initialization is performed by a constructor, the constructor must be declared as constexpr .

What is constexpr function in c++?

constexpr stands for constant expression and is used to specify that a variable or function can be used in a constant expression, an expression that can be evaluated at compile time. The key point of constexpr is that it can be executed at compile time.

Can constexpr throw?

Even though try blocks and inline assembly are allowed in constexpr functions, throwing exceptions or executing the assembly is still disallowed in a constant expression.

Can a member function be constexpr?

const can only be used with non-static member functions whereas constexpr can be used with member and non-member functions, even with constructors but with condition that argument and return type must be of literal types.


1 Answers

No, there is not a constexpr or similar usage keyword in C11. As to if it is planned in the future, the answer is "I don't know".

C11 §6.6 Constant expressions gives the constrains on constant expression:

Constant expressions shall not contain assignment, increment, decrement, function-call, or comma operators, except when they are contained within a subexpression that is not evaluated.

like image 114
Yu Hao Avatar answered Oct 03 '22 20:10

Yu Hao