Pay attention to no sign

zhaozj2021-02-16  175

Mixing the number of symbols and unsigned numbers in the C language is a need to pay attention to things, often see the following example:

1>

UNSIGNED INT URET;

IF (URET <0)

{.....}

Don't do it forever in parentheses

2>

Ulen = NEND - NSTART;

Memcpy (A, B, ULEN);

If Nend

3>

#define flags 0x80

CHAR Chret = 0x80;

... if (chret == flags) {Printf ("ok");}

Will not print OK, because the Chret will be converted to unsigned number.

So be careful not to symbolize, especially to transform the number of symbols to unparalleled numbers.

Some languages, such as Java, there is no signless number.

转载请注明原文地址:https://www.9cbs.com/read-8929.html

New Post(0)