â
Cã§ç¬¦å·ä»ãã©ãããå¤å®ãããã¯ããæ¸ãã¨ããã®ã¯æåãªåé¡ãªããã§ãããä¾ãã°
issigned(char) ==> charã符å·ä»ãªãã°1ãããã§ãªããªã0 issigned(short) ==> 1 issigned(unsigned int) ==> 0
ã®ãããªçµæãè¿ããã¯ããªãç°¡åã«æ¸ããããã§ãã
#define issigned(t) ((t)-1<0)
ã¨ãã£ãæãã§ããã§ãããã
ã§ã¯ãã©ã¡ã¿ãååã§ã¯ãªãã¦ãå¼ã ã£ããã©ãã§ããã
issigned(1) ==> 1 issigned(1U) ==> 0
ãããªãã¾ã æ¸ããããªæ°ããã¾ãããã§ã¯
issigned((short)1) ==> 1 issigned((unsigned char)1) ==> 0
ããµãã¼ãããã¨ãªã£ããããªããç¡çã£ã½ãæ°ããã¦ãã¾ããã
å°ãç°¡åã«ãã¦ããã©ã¡ã¿ã¯å¿ ã左辺å¤ã«éãã¨ãã¦ã¿ã¾ãããã
short x = 1; unsigned char y = 1; issigned(x) ==> 1 issigned(y) ==> 0
ãããªãã§ãããã ããã¡ãããã©ã¡ã¿ã«ä¸ããããå¤æ°ãå¤æ´ãã¦ã¯ããã¾ãããï¼
ãã¦ããããããæ¬é¡ã§ãä¸ã®æªå®ãªCã®ã³ã¼ããå®æããã¦æ±ããçµæãåºåããããã«ãã
#include <stdio.h> /* ããã«ã³ã¼ãã追å ããã*/ int main() { char c = 1; unsigned char uc = 1; signed char sc = 1; signed short ss = 1; unsigned short us = 1; signed int si = 1; unsigned int ui = 1; signed long sl = 1; unsigned long ul = 1; printf("c: %d\n", issigned(c)); printf("uc: %d\n", issigned(uc)); printf("sc: %d\n", issigned(sc)); printf("ss: %d\n", issigned(ss)); printf("us: %d\n", issigned(us)); printf("si: %d\n", issigned(si)); printf("ui: %d\n", issigned(ui)); printf("sl: %d\n", issigned(sl)); printf("ul: %d\n", issigned(ul)); printf("c : %d\n", issigned(char)); printf("sc: %d\n", issigned(signed char)); printf("uc: %d\n", issigned(unsigned char)); printf("ss: %d\n", issigned(signed short)); printf("us: %d\n", issigned(unsigned short)); printf("si: %d\n", issigned(signed int)); printf("ui: %d\n", issigned(unsigned int)); printf("sl: %d\n", issigned(signed long)); printf("ul: %d\n", issigned(unsigned long)); return 0; }
çµæã¯
c: 1 uc: 0 sc: 1 ss: 1 us: 0 si: 1 ui: 0 sl: 1 ul: 0 c : 1 sc: 1 uc: 0 ss: 1 us: 0 si: 1 ui: 0 sl: 1 ul: 0
ã¾ããçãã¯ããããããã¾ããããã£ã¨ãä¸çé¢ç®ã«è§£ãã¨
int main() { ... } #define main hoge
ã ãããã¡ããçé¢ç®åº¦ãé«ãã»ã©é«å¾ç¹ã