I know that ISO is a great deal about separating standard translation behavior and execution behavior, partially To ensure that the cross-execution environment of every goal has to be taken.
By that, I mean that the limited information available to the compiler in comparison to the running program is what you can do in the source code, such as the variables starting from a function based on the return value. Do not, like:
int twice (return) {return val * 2; } Int xyzzy = twice (7); Int main () {printf ("% d \ n", xyzzy); Return 0; } I'm curious about C ++ in this scheme since the literal evaluation depends on a function, so to stop the work such as: < Ul>
Returning a random value (even if depending on the input, such as 42_roughly do you value between 40 and 44)? Are there side effects like changing global effects? Is a function called to be called? Does it mean that no really is literally compiling in the sense of compiling time? If this is the case, what is the benefit of these liters on any other function call? In other words why:
int xyzzy = 1101_1110_b; Better than ?
It is a secret that you declare the form of constexpr or not User defined literal function in Compare it (normal performance-time function):
#include & lt; Iostream & gt; Int operator "" _twice (unsigned long long number) {return number * 2; } Int xyzzy = 7_twice; Int main () {std :: cout & lt; & Lt; Exxon & lt; & Lt; "\ N"; Return 0; } With this (compile-time static, static_assert works): #include < Iostream & gt; Constexpr int operator "_twice (unsigned long-term) {return number * 2;} int xyzzy = 7_twice; int main () {static_assert (7_twice == 14," time not constant compile "); Std :: cout & lt ; & Lt; eggt & lt; "\ n"; return 0;} Clearly, declare the constexpr function, all statements Also prohibits being constexpr , or compile-time constants; no random number shenanigans are allowed.
No comments:
Post a Comment