unsigned-char

Comparing unsigned char and EOF

眉间皱痕 提交于 2019-11-26 09:52:26
问题 when the following code is compiled it goes into an infinite loop: int main() { unsigned char ch; FILE *fp; fp = fopen(\"abc\",\"r\"); if(fp==NULL) { printf(\"Unable to Open\"); exit(1); } while((ch = fgetc(fp))!=EOF) printf(\"%c\",ch); fclose(fp); printf(\"\\n\",ch); return 0; } The gcc Compiler also gives warning on compilation abc.c:13:warning: comparison is always true due to limited range of data type the code runs fine when unsigned char is replaced by char or int as expected i.e. it

When is uint8_t ≠ unsigned char?

假如想象 提交于 2019-11-26 04:24:31
问题 According to C and C++, CHAR_BIT >= 8 . But whenever CHAR_BIT > 8 , uint8_t can\'t even be represented as 8 bits. It must be larger, because CHAR_BIT is the minimum number of bits for any data type on the system. On what kind of a system can uint8_t be legally defined to be a type other than unsigned char ? (If the answer is different for C and C++ then I\'d like to know both.) 回答1: If it exists, uint8_t must always have the same width as unsigned char . However, it need not be the same type;