When is stack space allocated for local variables?

前端 未结 5 2112
独厮守ぢ
独厮守ぢ 2021-01-02 02:54

I have a question about the following C code:

void my_function()
{
    int i1;
    int j1;

    // Do something...

    if (check_something())
    {
                 


        
5条回答
  •  佛祖请我去吃肉
    2021-01-02 03:57

    if "check_something()" is easily evaluated to 0, that whole block will be optimized out using a sufficiently high level of optimization. Yes, it's compiler-dependent. Generally, if you're checking the return value of a function call, it won't be optimized out. The best way to approach this would be to compiler it and actually look at the disassembly of the file to verify what you think is happening is actually happening.

提交回复
热议问题