【问题标题】:Clearing a struct variable for re-assigning清除结构变量以重新分配
【发布时间】:2014-06-04 03:27:51
【问题描述】:

我有一个返回我定义的结构类型的函数:

typedef struct irPulseSet
{
    int pulseCount;
    int (*pulses)[2];
} irPulseSet;

irPulseSet irReadPulse()
{
    irPulseSet outputPulseSet;
    //some stuff
    return outputPulseSet;
}

但我在循环中调用它:

while(1)
{
   irPulseSet currentlPulseSet = irReadPulse();
   //some other stuff here
}

我想知道如何取消设置currentPulseSet,以便在下一次while循环迭代中再次设置。

【问题讨论】:

    标签: c variables struct unset


    【解决方案1】:

    变量currentlPulseSet 存在于堆栈中。当它超出范围时,它将自动从内存中删除。您无需执行任何操作。

    【讨论】:

    • 所以它在每次循环迭代结束时出栈?
    • 是的,尝试在while()或do-while()表达式中使用,会发生什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 2019-11-24
    • 2018-03-29
    • 2016-03-20
    • 2011-09-04
    相关资源
    最近更新 更多