"If you wrote a compiler test, you wrote a call to the main one,"

A call maininside your program violates the C ++ standard

void f()
{
    main(); // an endless loop calling main ? No that not allowed
}

int main()
{
    static int = 0; 
    std::cout << i++ << std::endl;
    f(); 
}

In a lecture by Chandler Carrut, at about 10.40 p.m., he says

if you wrote a test with a compiler, you wrote a call main

How is this appropriate or how is the fact that the standard does not allow to be overcome?

+4
source share
1 answer

The point here is that if you are writing test code for the compiler, you will probably want to test the call mainusing several different sets of parameters, and that this can be done with an understanding of what you are going to use for verification.

main, main (, , POD ..). , , , , - , - , "" , main , ​​ . , main .

LLVM ( C, Clang), , main.

" " . , - , -, .

ALL undefined , - , , , - , .

, ( , MMU ), :

 char *ptr = (char *)0xA0000;
 ptr[0] = 'a';
 ptr[1] = 7;   // Determines the colour. 

undefined, , , C ++. , ... , UB, , Linux Windows ? VGA... [, , - , ]. , , - , , , . undefined , " UB", , .

+4

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


All Articles