指针立即变为NULL

pyt*_*nic 2 c++

我有以下LLVM代码.奇怪的是,在if块之外的新指令分配后si,类型的变量StoreInst立即变为null(0),而我已在外部范围声明它.这里发生了什么?

        Value *OldVal = NULL;
        StoreInst* si = NULL;

        if ( ... )
        {
            if ( ... )
            {
                ....

                if ( ... )
                {
                    ...
                    StoreInst* si = new StoreInst(...);
                    errs() << "si = " << si << "\n"; // Get some address here
                }
                errs() << "-->SI = " << si << "\n"; // Here I get NULL, why?
            }
            ...
        }
Run Code Online (Sandbox Code Playgroud)

我得到这样的输出,

si = 0x1822ba0
-->SI = 0x0
Run Code Online (Sandbox Code Playgroud)

And*_*rew 9

StoreInst* si = new StoreInst(...);- 您在si此处隐藏了主页名称

范围结束时}- 您会看到另一个指针的值

以下是您所做的一个示例:

int val = 0; //first val
{
    int val = 10; //other val (let's call it second)
    cout << val; //second val
} // second val is destroyed here
cout << val; //first val
Run Code Online (Sandbox Code Playgroud)

int为简单起见,我在示例中使用过.实际上它可以是任何类型