声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
Declare C++ array type with dynamic size works fine in Linux, but not Windows
使用最近的 gcc 版本,我可以声明动态大小的数组数据类型,如下所示:
#include <stdio.h>
int main() {
int u;
scanf("%d", &u);
using my_type = int[u];
printf("size of my_type: %dn", sizeof(my_type));
return 0;
}
这成功地与gcc编译,并且在Linux中工作正常。例如,输入 5 作为输入,这将打印 20。
但是对于Windows编译器cl.exe或VS2015本身,我收到编译错误:
error C2540: non-constant expression as array bound
我该如何解决这个问题?
这不是有效的便携式C++。这是GCC的C99扩展(可变长度数组(,在任何Visual Studio版本中都不可用。
相关文章:
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 编译在我的 Mac 上工作,但在集群 (Linux) 上不起作用
- 声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
- 为什么带lcov的codecov在Travis上不能正常工作,而在我当地的Linux Mint上却不能正常工作
- popen() 如何工作以及如何在 Linux 上实现它到 C++ 代码中
- Linux C++读取 UART 设备无法始终如一地工作
- Makefile在Linux中工作,但在Windows下不起作用,在子目录中找不到文件
- C++代码在 Linux 上按预期工作,但在 Windows 上则不然
- QtCUrl post不再工作(Linux nok...窗口确定)
- C++程序使用 mingw 在 Linux 上交叉编译在 MSy2 中工作,但不能直接在 Windows 中工作
- 将Linux打开,读,写,关闭功能以在Windows上工作
- Linux 中共享库中的单例无法按预期工作
- 为什么我的文件/目录操作在Windows上工作正常,但在Linux上不能
- C++:printf 和 wprintf 不能一起工作 (Linux)
- 在macOSX上编译boost_asio/example/ssl/server.cpp可以在Linux上工作
- 为什么这个c++代码在Linux中可以正常工作,而在Windows中却不能
- 可执行文件无法正常工作 [Linux]
- 无法在 Linux 上进行回车工作
- 哔哔声不工作(linux)
- Qt 5.3 QSystemTrayIcon不正常工作[Linux]