使用的目的/优势/区别是什么?
/* C89 compliant way to cast 'char' to 'unsigned char'. */
static inline unsigned char
to_uchar (char ch)
{
return ch;
}
Run Code Online (Sandbox Code Playgroud)
与标准演员相比?
也许编写该函数的程序员不喜欢强制转换语法......
foo(to_uchar(ch)); /* function call */
foo((unsigned char)ch); /* cast */
Run Code Online (Sandbox Code Playgroud)
但无论如何我都会让编译器担心它:)
void foo(unsigned char);
char s[] = "bar";
foo(s[2]); /* compiler implicitly casts the `s[2]` char to unsigned char */
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
353 次 |
| 最近记录: |