c++ - 使用 Visual Studio C++ 编译器编译 C 代码是否有任何(与性能相关的)缺点?

标签 c++ c visual-studio-2010

这是我第一次使用 Visual Studio (2010) 进行开发,我注意到:

int *x = malloc(sizeof(int) * 50);

当我尝试构建“main.c”时出现错误。我假设这是因为 VS 使用其 C++ 编译器来构建 C 程序。

VS 为 C 生成的代码是否与 Windows 下一样好,还是我应该寻找更好的和/或 C 独有的代码?

最佳答案

I'm assuming this is because VS is using its C++ compiler to build C programs.

您的假设是不正确的:该行代码没有任何问题,事实上 Visual C++ 会毫无错误地编译它:

c:\dev>type stubby.c
#include <stdlib.h>

int main(void)
{
    int *x = malloc(sizeof(int) * 50);
}

c:\dev>cl stubby.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

stubby.c
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:stubby.exe
stubby.obj

c:\dev>

Visual C++ 是否适合您的需求取决于您的需求是什么。不支持C99;如果对 C99 的支持对您来说很重要,那么您将需要寻找另一个编译器。它不支持过多的 GNU 语言扩展;如果这些对您很重要,您会想要找到另一个编译器。

关于c++ - 使用 Visual Studio C++ 编译器编译 C 代码是否有任何(与性能相关的)缺点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5590459/

相关文章:

c++ - 如何在 C 中构造具有绝对整数值和等效 char 整数值的 char 数组?

c++ - C vs C++ 在 VS2015 中使用 cl 编译器

c++ - boost::system::error_code 产生错误 158 未知

java - 为什么静态变量在 Java 方法中不允许像在 C/C++ 函数中那样?

c - 如何不阻止设备被弹出/安全移除?

c - 奇怪函数 "printf"的输出精度

visual-studio-2010 - 如何在 VS 2010 UML 类图参数化类型中为类型参数添加多个泛型类型约束?

c - 使用 VS2010 构建的应用程序在 VS-Express2008 中不起作用 - C

.net - Visual Basic,当我唯一的引用是 "System.Drawing"时,为什么我不能导入 "System"?

c++ - const 正确清洗 pod(普通旧数据)