Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译器如何管理返回内联函数?_C++_Function_Compiler Construction_Inline - Fatal编程技术网

C++ 编译器如何管理返回内联函数?

C++ 编译器如何管理返回内联函数?,c++,function,compiler-construction,inline,C++,Function,Compiler Construction,Inline,假设我有一个内联函数,如: 当然,当它到达return语句时,必须忽略函数的其余部分(即inside1和inside2),因为return。但是如果我从父函数(Process())返回,它会立即返回,因此我永远看不到100 这意味着它以另一种方式进行 编译器如何处理这种情况?我试图创建一个代码块,但是return仍然返回到主函数…在编写“仿真”时,您忘记处理一个returns。在内联函数中,编译器会用goto语句替换它 void Process() { double value;

假设我有一个内联函数,如:

当然,当它到达
return
语句时,必须忽略函数的其余部分(即
inside1
inside2
),因为
return
。但是如果我从父函数(
Process()
)返回
,它会立即返回,因此我永远看不到
100

这意味着它以另一种方式进行

编译器如何处理这种情况?我试图创建一个代码块,但是
return
仍然返回到主函数…

在编写“仿真”时,您忘记处理一个
return
s。在内联函数中,编译器会用
goto
语句替换它

void Process() {
    double value;

    // begin of inlined function

    // some condition
    if (true) {
        // some other condition
        if (true) {
            // another condition
            if (true) {
                value = 1.0;
                goto next;     // <<<<<<<<<<<<<<<<<<<  return replaced by goto
            }

            // somethings
            std::cout << "inside1" << std::endl;
        }

        // somethings
        std::cout << "inside2" << std::endl;
    }

    value = 2.0; 
 next:   
    //end of inlined function

    value *= 100.0;

    std::cout << value << std::endl;
}
void进程(){
双重价值;
//内联函数的开始
//某些条件
如果(真){
//其他条件
如果(真){
//另一种情况
如果(真){
数值=1.0;

转到下一步;//在这种情况下,内联代码将把
返回处理为
转到
,例如:

void Process() {
    double value;

    // some condition
    if (true) {
        // some other condition
        if (true) {
            // another condition
            if (true) {
                value = 1.0;
                goto nextStep;
            }

            // somethings
            std::cout << "inside1" << std::endl;
        }

        // somethings
        std::cout << "inside2" << std::endl;
    }

    value = 2.0; 

nextStep:

    value *= 100.0;

    std::cout << value << std::endl;
}
void进程(){
双重价值;
//某些条件
如果(真){
//其他条件
如果(真){
//另一种情况
如果(真){
数值=1.0;
转到下一步;
}
//有些事

显然,cout编译器不使用return,我不知道具体使用哪一个,但是还有很多其他选项,比如
while(1){…break;}
或者甚至是
goto
,或者一些更模糊的步骤,其结果是asm
inline
不会改变函数调用的语义,只会改变函数调用的链接。
goto
对编程来说不是坏事吗?:)你认为
if then else
的幕后黑手是什么?
goto
本身并不坏(就像一把刀),只有它的用法可以是好的或坏的。@Jean BaptisteYunès paizza的评论可能是讽刺的。我是讽刺的:)谢谢你澄清这一点!
void Process() {
    double value;

    // begin of inlined function

    // some condition
    if (true) {
        // some other condition
        if (true) {
            // another condition
            if (true) {
                value = 1.0;
                goto next;     // <<<<<<<<<<<<<<<<<<<  return replaced by goto
            }

            // somethings
            std::cout << "inside1" << std::endl;
        }

        // somethings
        std::cout << "inside2" << std::endl;
    }

    value = 2.0; 
 next:   
    //end of inlined function

    value *= 100.0;

    std::cout << value << std::endl;
}
void Process() {
    double value;

    // some condition
    if (true) {
        // some other condition
        if (true) {
            // another condition
            if (true) {
                value = 1.0;
                goto nextStep;
            }

            // somethings
            std::cout << "inside1" << std::endl;
        }

        // somethings
        std::cout << "inside2" << std::endl;
    }

    value = 2.0; 

nextStep:

    value *= 100.0;

    std::cout << value << std::endl;
}