Call a function without argument, although it needs one [K&R-C]

前端 未结 3 1990
野性不改
野性不改 2021-01-13 13:42

It\'s K&R-C and here is the code: http://v6shell.org/history/if.c

Look at the main-Method. There is this line \"if(exp())\".

But the function exp is decl

3条回答
  •  无人共我
    2021-01-13 14:11

    Ultimately, it is a bug in the Unix V6 shell support command, if.

    The code for the function is:

    exp(s) {
        int p1; 
    
        p1 = e1();
        if (eq(nxtarg(), "-o")) return(p1 | exp());
        ap--;
        return(p1);
    }
    

    The function parameter s, implicitly of type int (as is the function iteself), is actually unused in the function, so the bug is the presence of s, not the absence of an argument in the calls to exp(). All the calls with zero actual arguments are correct.

提交回复
热议问题