Search code examples
c++visual-studio-2010program-entry-pointundef

#undef main gives no result


I'm working with MVisualC++ 2010 and when I try to undefine the "main", there's no result and the console launches as usual. I was expecting some missing entry point error or something. Why is that?

#undef main
int main()
{
}

Solution

  • main isn't a #define in the first place. Your #undef changes nothing at all.

    #define foo bar tells the preprocessor "replace all occurences of foo with bar". #undef foo tells the preprocessor "foo has no special meaning anymore, leave it as is"

    If you want a linker error, rename main to e.g. main2, or do e.g. this:

    void foo();
    int main() {
      foo();
    }
    

    This tells the compiler that a foo function exists (but not what it is). main tries to use it, so the linker will give an error when it can't find it.