如果将负数传递给vxworks中的taskDelay函数,会发生什么?
注意,taskDelay 的参数是 int 类型,这意味着该数字可以为负数。 只是想知道传递负数时函数将如何反应。
Noted that the parameter of taskDelay is of type int, which means the number could be negative. Just wondering how the function is going to react when passing a negative number.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
大多数函数都会验证输入,并且只返回早期/返回 0/将相关参数设置为默认值。
Most functions would validate the input, and just return early/return 0/set the parameter in question to a default value.
我认为在生产中没有必要这样做,并且您可能有一些可以测试的代码......为什么不尝试一下呢?
I presume there's no critical need to do this in production, and you probably have some code lying around that you could test with.... why not give it a go?
文档没有解决这个问题,并且他们定义的唯一错误代码并不涵盖这种情况。 因此,最正确的答案是结果未定义。
不过,请参阅 VxWorks / Tornado II 常见问题解答了解此宝石:
假设这个错误是旧的,我希望它要么返回错误,要么执行与 taskDelay(0) 相同的操作,这会将您的任务置于就绪队列的末尾。
The documentation doesn't address it, and the only error codes they do define doesn't cover this case. The most correct answer therefore is that the results are undefined.
See the VxWorks / Tornado II FAQ for this gem, however:
Assuming this bug is old, I would hope that it would either return an error or do the same thing as taskDelay(0), which puts your task at the end of the ready queue.
对于taskDelay(10),任务延迟刻度实际上为10,9,..,1,0。
对于 taskDelay(-10),任务延迟刻度实际上为 -10,-11,...,-2147483648,2147483647,...,1,0。
The task delay tick will be VIRTUALLY 10,9,..,1,0 for taskDelay(10).
The task delay tick will be VIRTUALLY -10,-11,...,-2147483648,2147483647,...,1,0 for taskDelay(-10).