Last active
November 17, 2016 04:29
-
-
Save t-nissie/a939d8c856cea1bd936eb5d61d9979f1 to your computer and use it in GitHub Desktop.
Qiitaの卜部昌平著『Cで飽和++』のコードのコピペ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* saturated_inc(x) http://qiita.com/shyouhei/items/e960e641882da80c8932 */ | |
#if __GNUC__ >= 7 | |
# define saturated_inc(x) __builtin_add_overflow_p(x, 1, x) ? x : ++x | |
#else | |
# define saturated_inc(x) ({__typeof__(x) y; __builtin_add_overflow(x, 1, &y) ? x : ++x; }) | |
#endif | |
signed long long | |
func(signed long long x) | |
{ | |
return saturated_inc(x); | |
} | |
//Local variables: | |
//compile-command: "gcc -O3 -S -o- saturated.c" | |
//End: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment