LoginSignup
0
2

More than 5 years have passed since last update.

C > mistake > ++ > 1日(24*60*60秒)を超えない | 別のハマリ事象 (0..255のループ)

Last updated at Posted at 2018-07-26
動作環境
C (ideone gcc 6.3)

#include <stdio.h>
#include <stdint.h>

int main(void) {
    int16_t val = 32764;

    for(int loop=0; loop<10; loop++) {
        printf("%d\n", val);
        val++;
    }

    return 0;
}
実行結果
32764
32765
32766
32767
-32768
-32767
-32766
-32765
-32764
-32763

上記のvalに対してif (val > (24 * 60 * 60)の判定をしても成立することはない。
1日は86400秒。

関連

教えていただいた事項

(追記 2018/07/26)

@tenmyo さんのコメントにおいて別のハマリ事象を教えていただきました。

情報感謝です。

0
2
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2