What is meant by "using a function"

$ 3.6.1 / 3 condition -

"The main function should not be used (3.2) inside the program.".

The example of an academically motivated program below uses the name "main" in several ways, which I thought were legal. This is based on the assumption that “using a function” is associated with a function call (directly / indirectly).

struct MyClass{ 
private: 
   MyClass(){}  
   friend int main(); 
};   

int main(){  
   MyClass m;  
   int (*p)() = main; // but don't do anything 
}
  • Fairly honest, the code shown is compiled using gcc / VS 2010.

  • I am surprised by Como's mistake.

Comeau online gives an error when declaring 'p' (that is, when referring to "main"), but not when declaring "main" as a friend.

Who / What is correct regarding C ++ 03?

+3
4

++ 03 §3.2/2 :

, .

, ; .

.

main() p, (++ 03 §3.2/2):

, , (. 5.19), sizeof (5.3.3) typeid lvalue (5.2.8).

+6

++ 03 C.1 ++ ISO C :

3.6

: Main
. .
:
: : , ​​ mymain (argc, argv.
:

+1

( " " ), , , . - - . main(), .

( ) main() , . , main , ( , , , ).

0

, friend "- , main", ", THE ONE main? ".

0

Source: https://habr.com/ru/post/1761654/


All Articles