1
我使用XLookupString将一个关键事件映射到ASCII字符串,keysym和ComposeStatus。在位操作中使用'char'变量
int XLookupString(event_structure, buffer_return, bytes_buffer, keysym_return, status_in_out)
XKeyEvent *event_structure;
char *buffer_return; /* Returns the resulting string (not NULL-terminated). Returned value of the function is the length of the string. */
int bytes_buffer;
KeySym *keysym_return;
XComposeStatus *status_in_out;
这里是我的代码:
char mykey_string;
int arg = 0;
------------------------------------------------------------
case KeyPress:
XLookupString(&event.xkey, &mykey_string, 1, 0, 0);
arg |= mykey_string;
但使用位操作“字符”变量,符号扩展会产生意想不到的效果。 我可以防止这个?
感谢
从本质上讲,位运算是基于无符号整数。所以建议你应该使用unsigned char和unsigned int来代替。顺便说一句,VC++默认将char视为未签名,您可以通过编译器选项指定char类型的符号。 – xmllmx