我在Visual Studio 2008的C和C++构建环境中编写了相同的代码行,但C代码的目标文件大小为5.5kb,C++代码文件大小为6.17 kb.为什么会有这种差异?
以下是两种环境中的代码:
#include <stdio.h>
struct S
{
char c;
};
void func()
{
int i;
int j;
printf("%d", i);
}
int main()
{
struct S s;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
仅仅因为你的代码在C和C++中有不同的含义.
main)i的调用printf具有未定义的行为.两种语言都可能会决定拍摄你的不同策略.