开发者

Are there global asserts in C?

开发者 https://www.devze.com 2023-03-31 12:32 出处:网络
Say I have a program where the value of an integer i should never be negative. Is there a way I can insert a global assert(i>=0) such that whenever i becomes negative an error is reported. This can

Say I have a program where the value of an integer i should never be negative. Is there a way I can insert a global assert(i>=0) such that whenever i becomes negative an error is reported. This can be very useful while debuggi开发者_如何学JAVAng. I don't want to put an assert everywhere the value of i is manipulated.


No.

Your debugger might have this sort of facility, though. For instance, GDB has watchpoints.


No. You'll have to pick a point in the program's execution to keep checking that variable/assert.


Why don't you just declare i as unsigned?

0

精彩评论

暂无评论...
验证码 换一张
取 消