We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
constexpr
web 端
原文:
#include <iostream> #define LEN 10 int len_foo() { int i = 2; return i; } constexpr int len_foo_constexpr() { return 5; } constexpr int fibonacci(const int n) { return n == 1 || n == 2 ? 1 : fibonacci(n-1)+fibonacci(n-2); } int main() { char arr_1[10]; // 合法 char arr_2[LEN]; // 合法 int len = 10; // char arr_3[len]; // 非法 const int len_2 = len + 1; constexpr int len_2_constexpr = 1 + 2 + 3; // char arr_4[len_2]; // 非法 char arr_4[len_2_constexpr]; // 合法 // char arr_5[len_foo()+5]; // 非法 char arr_6[len_foo_constexpr() + 1]; // 合法 std::cout << fibonacci(10) << std::endl; // 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 std::cout << fibonacci(10) << std::endl; return 0; }
(省略代码解释...)
注意,现在大部分编译器其实都带有自身编译优化,很多非法行为在编译器优化的加持下会变得合法,若需重现编译报错的现象需要使用老版本的编译器。
这段描述基本可以说是在胡说八道。
gcc
clang
-pedantic-errors
The text was updated successfully, but these errors were encountered:
Modified the error description in the constexpr section.changkun#289
2372cb4
卢瑟,链接都给错了😡
Sorry, something went wrong.
这个书目前是什么情况呀,几乎隔段就是错误,好像一直没有维护,在线版本完全没有修订和更新,完全缺乏可读性了。
Successfully merging a pull request may close this issue.
web 端
原文:
这段描述基本可以说是在胡说八道。
gcc
、clang
等编译器默认情况下部分支持了 C 语言的特性:“变长数组”,才让定义的数组时,长度可以是非常量表达式。测试。-pedantic-errors
。测试。The text was updated successfully, but these errors were encountered: