Questions tagged «openbsd»

6
C指向按位和运算符的数组声明的指针
我想了解以下代码: //... #define _C 0x20 extern const char *_ctype_; //... __only_inline int iscntrl(int _c) { return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _C)); } 它源自obenbsd操作系统源代码中的文件ctype.h。此函数检查char是ascii范围内的控制字符还是可打印的字母。这是我目前的思路: 调用iscntrl('a')并将'a'转换为其整数值 首先检查_c是否为-1,然后返回0,否则... 将未定义指针指向的地址加1 声明此地址为长度数组的指针(unsigned char)((int)'a') 将按位和运算符应用于_C(0x20)和数组(???) 奇怪地,它以某种方式起作用,并且每次返回0时,给定的char _c都不是可打印字符。否则,当该函数可打印时,它只会返回一个没有特殊意义的整数值。我的理解问题在于第3步,第4步(有点)和第5步。 感谢您的任何帮助。
9 c  openbsd 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.