我看到了这段时间的实施strcmp,我有一个纯粹教育目的的问题.为什么需要将输入转换为16位整数,进行数学运算然后转换回8位?在8bit中进行减法有什么问题?
int8_t strcmp (const uint8_t* s1, const uint8_t* s2)
{
while ( *s1 && (*s1 == *s2) )
{
s1++;
s2++;
}
return (int8_t)( (int16_t)*s1 - (int16_t)*s2 );
}
Run Code Online (Sandbox Code Playgroud)
注意:代码假定为16位int类型.
编辑:
有人提到C int默认转换为(假设为32位).即使代码明确声明要转换为16位,情况也是如此int吗?
c ×1