Function inside function

function1()
    {
        statement1;
        statement2;
        function2()
        {
                statement3;
                statement3;
        }
    } 

why control is not included in function2, although the return type of both functions is the same

+3
source share
4 answers

If you want to enter function2, you must call it. The fact that you put it in another function does not mean that it will be executed, but it is still declared and defined. You must explicitly call him

function1()
    {
    statement1;
    statement2;
    function2()
    {
            statement3;
            statement3;
    }
 function2();

} 

Indeed, Std C does not allow this. But it still depends on your compiler, so if you do this for a specific purpose, check with your compiler, otherwise just pull the Function2 declaration from function1 block

+11
source

This is not legal C as defined by the standard. Does it even compile?

. , GCC, CoolStraw .

+5

: C

+3

, CoolStraw , , , . . , , .

, C. gcc, IBM XLC.

int K & R C 1970 C . gcc. , ; , "#include" , , int. , , 64- 32- ints, , .

Many compilers may give some kind of warning that you have omitted a function type, and many also warn that you are calling a non-void function without using a result. Both are legal, both may be exactly what you intended, but both may be mistakes. And most compilers can also warn of non-standard compatible extensions, such as nested gcc functions. If you care about portability, include such warnings.

+1
source

All Articles