2

Why is this piece of code working in Visual Studio Express 2012?

struct S{int k;};
int main(S s)
{
s.k = 100;
// other lines
}

I read both the standards document and MSDN but didn't find any mention of prohibiting this kind of overloads of main although this MSDN page says nothing more than Cannot be overloaded . Does that imply it is allowed if the implementation likes it? Or it is simply a bug in the compiler?


From what I gather from the initial comments to this question, and the discussion in the question this is marked duplicate of, suitable overloads are allowed by the implementation as long as the canonical ones are supported. However, of what use is it to allow the kind of overload that I mention? The environment has no idea of the structure to populate it and pass it as the argument during start up. Shouldn't it be a bug?

There may be an obscure (from my POV) situation where the program may be loaded by custom loader which sets up the arguments etc. Is that the reason this is allowed?

Community
  • 1
  • 1
vin
  • 181
  • 2
  • 10
  • 1
    Allowing `void main()` should be considered as a bug in the compiler. The only valid syntax for `main()` are `int main()` or `int main(int argc,char* argv[])` – πάντα ῥεῖ Dec 31 '14 at 11:25
  • No, an implementation is allowed to provide other forms of main and still be considered conforming. The two mentioned forms are the only portable ones that every implementation must provide. – n. m. could be an AI Dec 31 '14 at 11:31
  • 2
    Neither `void main()` nor `void main(S)` are forms C++ allows. C++ does allow implementations to accept other forms of `main`, but it requires any of the other forms to still have a return type of `int`. –  Dec 31 '14 at 11:36

0 Answers0