#include
#include
/*
* __ctype_b_loc
*
* 单字节类型判断
*/
#if 0
/* These are defined in ctype-info.c.
The declarations here must match those in localeinfo.h. */
/* __ctype_b_loc 申明 */
extern const unsigned short int **__ctype_b_loc (void)
__THROW __attribute__ ((__const__));
/* __isctype 宏定义,调用__ctype_b_loc */
# define __isctype(c, type) \
((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
/* 大小端转换 */
# include
# if __BYTE_ORDER == __BIG_ENDIAN
# define _ISbit(bit) (1 << (bit))
# else /* __BYTE_ORDER == __LITTLE_ENDIAN */
# define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
# endif
/* 枚举值 */
enum
{
_ISupper = _ISbit (0), /* UPPERCASE. */
_ISlower = _ISbit (1), /* lowercase. */
_ISalpha = _ISbit (2), /* Alphabetic. */
_ISdigit = _ISbit (3), /* Numeric. */
_ISxdigit = _ISbit (4), /* Hexadecimal numeric. */
_ISspace = _ISbit (5), /* Whitespace. */
_ISprint = _ISbit (6), /* Printing. */
_ISgraph = _ISbit (7), /* Graphical. */
_ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */
_IScntrl = _ISbit (9), /* Control character. */
_ISpunct = _ISbit (10), /* Punctuation. */
_ISalnum = _ISbit (11) /* Alphanumeric. */
};
#define __exctype(name) extern int name (int) __THROW
__exctype (isdigit); /* extern int isdigit (int) __THROW ---> isdigit 函数申明 */
/* isdigit 函数定义, 调用 __isctype, __isctype 再调用 __ctype_b_loc */
# define isdigit(c) __isctype((c), _ISdigit) /* (*__ctype_b_loc ())[(int) (c)] & _ISdigit */
#endif
int main()
{
printf("0x%x\n", _ISdigit); /* 0x800 */
printf("0x%x\n", isdigit('1')); /* 0x800 */
printf("0x%x\n", isdigit('-')); /* 0x0 */
return 0;
}
#if 0
/*
* intel
*/
0000000000001169 :
1169: f3 0f 1e fa endbr64
116d: 55 push %rbp
116e: 48 89 e5 mov %rsp,%rbp
1171: be 00 08 00 00 mov $0x800,%esi // 0x800
1176: 48 8d 3d 87 0e 00 00 lea 0xe87(%rip),%rdi # 2004 <_IO_stdin_used+0x4> // rdi="0x%x\n"
117d: b8 00 00 00 00 mov $0x0,%eax
1182: e8 d9 fe ff ff callq 1060 // printf(rdi, rsi)
1187: e8 e4 fe ff ff callq 1070 <__ctype_b_loc@plt> // rax=0x7ffff7fac4d8 --> **__ctype_b_loc
// 0x7ffff7fac4d8: 0x7ffff7f553c0
118c: 48 8b 00 mov (%rax),%rax // rax=0x7ffff7f553c0 --> *__ctype_b_loc
// 0x7ffff7f553c0 <_nl_C_LC_CTYPE_class+256>: 0x0002000200020002
118f: 48 83 c0 62 add $0x62,%rax // rax=0x7ffff7f553c0+0x62=0x7ffff7f55422 --> *__ctype_b_loc+0x62
// 0x7ffff7f55422 <_nl_C_LC_CTYPE_class+354>: 0xd808d808d808d808
1193: 0f b7 00 movzwl (%rax),%eax // eax=0xd808 --> __ctype_b_loc+0x62
1196: 0f b7 c0 movzwl %ax,%eax // ax=0xd808, eax=ax=0xd808
1199: 25 00 08 00 00 and $0x800,%eax // eax=0xd808 & 0x800 = 0x800
119e: 89 c6 mov %eax,%esi // esi=eax
11a0: 48 8d 3d 5d 0e 00 00 lea 0xe5d(%rip),%rdi # 2004 <_IO_stdin_used+0x4> // rdi="0x%x\n"
11a7: b8 00 00 00 00 mov $0x0,%eax
11ac: e8 af fe ff ff callq 1060 // printf(rdi, esi)
11b1: e8 ba fe ff ff callq 1070 <__ctype_b_loc@plt> // rax=0x7ffff7fac4d8
// 0x7ffff7fac4d8:0x7ffff7f553c0
11b6: 48 8b 00 mov (%rax),%rax // rax=0x7ffff7f553c0
// 0x7ffff7f553c0 <_nl_C_LC_CTYPE_class+256>: 0x0002000200020002
11b9: 48 83 c0 5a add $0x5a,%rax // rax=0x7ffff7f553c0+0x5a = 0x7ffff7f5541a
// 0x7ffff7f5541a <_nl_C_LC_CTYPE_class+346>: 0xd808c004c004c004
11bd: 0f b7 00 movzwl (%rax),%eax // eax=0xc004
11c0: 0f b7 c0 movzwl %ax,%eax // eax=0xc004 ah=0xc0, al=0x04
11c3: 25 00 08 00 00 and $0x800,%eax // eax = 0xc004 & 0x800 = 0x0
11c8: 89 c6 mov %eax,%esi
11ca: 48 8d 3d 33 0e 00 00 lea 0xe33(%rip),%rdi # 2004 <_IO_stdin_used+0x4>
11d1: b8 00 00 00 00 mov $0x0,%eax
11d6: e8 85 fe ff ff callq 1060
11db: b8 00 00 00 00 mov $0x0,%eax
11e0: 5d pop %rbp
11e1: c3 retq
11e2: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
11e9: 00 00 00
11ec: 0f 1f 40 00 nopl 0x0(%rax)
#endif