0

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()
{
}
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Neomex
  • 1,650
  • 6
  • 24
  • 38

1 Answers1

7

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.

Erik
  • 88,732
  • 13
  • 198
  • 189
  • So if I undef main while using SDL, I don't work with standard library, just with something that is implemented in SDL? – Neomex Mar 05 '11 at 09:55
  • If someone tells you not to define main, it means "don't create a main function". The term define is not the same as `#define`, it means "create this function/variable" – Erik Mar 05 '11 at 09:58
  • On SDL, I don't use this, but I believe what it does is to use a #define to "rename" main. Your #undef would, in that case, cancel the renaming and SDL's own `main` would not be called. – Erik Mar 05 '11 at 10:01