【发布时间】: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++ 有问题,但我不明白为什么这应该是个问题。
感谢您的帮助。
【问题讨论】:
-
你有一个 combination of unspecified and undefined behavior 它是未指定的 b/c func 参数的评估顺序未指定和未定义 b/c 你在一个序列点内对同一个变量进行了多次修改。
标签: c