F
Francois Grieu
Consider this macro
// check if x, assumed of type unsigned char, is in range [0x20..0x7E]
#define ISVALID(x) ((x)>=0x20 && (x)<=0x7E)
Of course, this can't be safely used as in
if (ISVALID(*p++)) foo();
where p is a pointer ot unsigned char.
Unless I err, this issue can be fixed (and often, performance
improved) using
#define ISVALID(x) ((unsigned char)((x)-0x20)<=0x7E-0x20)
Buf can we do something similar about this one?
// check if x, assumed of type unsigned char,
// is in range [0x20..0x7E] or at least 0xC0
#define ISVALID(x) ((x)>=0x20 && (x)<=0x7E || (x)>=0xC0)
Francois Grieu
[reposted with a fix in the last comment]
// check if x, assumed of type unsigned char, is in range [0x20..0x7E]
#define ISVALID(x) ((x)>=0x20 && (x)<=0x7E)
Of course, this can't be safely used as in
if (ISVALID(*p++)) foo();
where p is a pointer ot unsigned char.
Unless I err, this issue can be fixed (and often, performance
improved) using
#define ISVALID(x) ((unsigned char)((x)-0x20)<=0x7E-0x20)
Buf can we do something similar about this one?
// check if x, assumed of type unsigned char,
// is in range [0x20..0x7E] or at least 0xC0
#define ISVALID(x) ((x)>=0x20 && (x)<=0x7E || (x)>=0xC0)
Francois Grieu
[reposted with a fix in the last comment]