上級 › Assertion failed の原因と直し方 › パターン3
Assertion failed の原因と直し方
assert()に渡した条件式がその場でfalseになったときに強制終了するマクロです。
1 #include <stdio.h> 2 #include <assert.h> 3 4 int main(void) { 5 int temp = 36; 6 assert(__________); ^ 7 printf("temp=%d\n", temp); 8 return 0; 9 }
main: main.c:6: main: Assertion `temp < 0' failed.
Aborted
空欄を埋めてコンパイル・実行を通す
assertは「本来ありえないはずの状態」を検出するためのものです。前提そのものを書き間違えると、正常な値でも強制終了の原因になります。
次の問題