小编Tac*_*chi的帖子

constexpr new 如何分配内存?

我们如何在编译时动态分配?是否constexpr operator new只是在栈上分配内存?

c++ new-operator constexpr c++20

3
推荐指数
2
解决办法
1071
查看次数

GCC 关于将其作为 VLA 的说法正确吗?

这个问题与“ Are conformant arrayparameters VLAs? ”非常相似,唯一的区别是这里我在数组声明的andstatic中使用关键字(C99 中引入),这意味着声明的数组应该有空间至少对于元素。这是一个例子:[]len

\n
#include <stddef.h>\n#include <stdio.h>\n\nvoid print_array(size_t len, const int arr[static len]) {\n    for (size_t i = 0; i < len; i++) {\n        printf("%d\\n", arr[i]);\n    }\n}\n\nint main(void) {\n    const int arr[] = {1, 2, 3, 4};\n    print_array(sizeof arr / sizeof *arr, arr);\n    return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n

当在 GCC 和 Clang 上使用该-Wvla标志编译此代码时,会发出以下警告:

\n
main.c:4:1: warning: ISO C90 forbids variable length array \xe2\x80\x98arr\xe2\x80\x99 [-Wvla]\n    4 | void print_array(size_t len, const int …
Run Code Online (Sandbox Code Playgroud)

c c99 language-lawyer

3
推荐指数
1
解决办法
134
查看次数

标签 统计

c ×1

c++ ×1

c++20 ×1

c99 ×1

constexpr ×1

language-lawyer ×1

new-operator ×1