【问题标题】:Strange warning about operation may be undefined for var++ [duplicate]var ++可能未定义有关操作的奇怪警告[重复]
【发布时间】:2014-09-13 09:52:55
【问题描述】:

我是 C 新手,但我目前正在做一个项目,但遇到了一个奇怪的问题。

我有以下代码:

int insertID = 0;
asprintf(&inboundSql, "INSERT INTO DataTable VALUES (%i, %i, '%s', '%s', %i),"
        "(%i, %i, '%s', '%s', %i), (%i, %i, '%s', '%s', %i), (%i, %i, '%s', '%s', %i),"
        "(%i, %i, '%s', '%s', %i), (%i, %i, '%s', '%s', %i)",
        dataRow, D_DATE, callLogSearchData[dataRow].date, epochBuffer, insertID++,
        dataRow, D_TIME, callLogSearchData[dataRow].time, epochBuffer, insertID++,
        dataRow, D_APARTY, callLogSearchData[dataRow].aParty, epochBuffer, insertID++,
        dataRow, D_BPARTY, callLogSearchData[dataRow].bParty, epochBuffer, insertID++,
        dataRow, D_DURATION, durationBuffer, epochBuffer, insertID++,
        dataRow, D_RESULT, callLogSearchData[dataRow].cleardownCause, epochBuffer, insertID++);

当我编译代码时,我得到以下信息:

warning: operation on insertID may be undefined

即使我收到上述警告,我的代码仍按预期工作,所以我不明白问题出在哪里。我猜它认为执行 insertID++ 有问题,但我不明白为什么这应该是个问题。

感谢您的帮助。

【问题讨论】:

标签: c


【解决方案1】:

这是因为在 C 中计算函数参数的确切顺序没有定义。因此,您无法确定 insertID++ 的价值。要解决此问题,您应该在调用 asprintf() 之前正确计算传递不同变量的值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多