I'm working on a program that handles UTF-8 characters.  I've made the following macros to detect UTF-8. I've tested them with a few thousand words and they seem to work.I'll add another one to do error-checking later, but for now I would like to know what mistakes I've made and how these macros can be improved. //check if value is in range of leading byte#define IS_UTF8_LEADING_BYTE(b) (((unsigned char)(b) >= 192) && (unsigned char)(b) < 248)//check if value is in range of sequence byte#define IS_UTF8_SEQUENCE_BYTE(b) ((unsigned char)(b) >= 128 && (unsigned char)(b) < 192)//can be any utf8 byte, first, last...#define IS_UTF8_BYTE(b) (IS_UTF8_LEADING_BYTE(b) || IS_UTF8_SEQUENCE_BYTE(b))//no error checking, it must be used only on leading byte#define HOW_MANY_UTF8_SEQUENCE_BYTES(b) ((((unsigned char)(b) & 64) == 64) + (((unsigned char)(b) & 32) == 32) + (((unsigned char)(b) & 16) == 16)) 
Macros to detect UTF-8
c;macros;utf 8
If you are sure that you have only valid encoded UTF8, you can simplify#define IS_UTF8_BYTE(b) (IS_UTF8_LEADING_BYTE(b) || IS_UTF8_SEQUENCE_BYTE(b))to#define IS_UTF8_BYTE(b) ((unsigned char)(b) >= 128)because every byte that is not ASCII must be an UTF8-byte.