Visual Studio 2008编译C++文件中的任何内容?

Bra*_*ers 3 c++ visual-studio-2008

我今天注意到项目中的源代码文件正在编译,即使它顶部有垃圾.它让我想知道通过编译器会通过什么都没有错误.以下是不会生成任何错误消息的代码示例:

what kind of weird behaviour is this???

#include "stdafx.h"

// what is up?

int foo(int bar)
{
    bla bla bla?????
    return bar;
}

and more junk???
Run Code Online (Sandbox Code Playgroud)

编译器在世界上做了什么来允许编译代码而不给出任何错误消息?我正在使用Visual Studio 2008,这是非托管的C++代码.foo函数实际上并不在目标文件中生成,因此无法使用,但为什么没有错误?

blu*_*her 7

#include "stdafx.h"行之前的部分实际上是可解释的(假设文件实际已编译):如果启用了预编译头文件(默认情况下),则忽略该行之前和之后的所有内容.有关简短摘要,请参阅Wikipedia on Precompiled Headers.

但是,如果包含下面的语法错误代码没有生成错误,则可能根本没有编译您的文件.