hi i am interested in those chars which are representable by ascii table. for that reason i am doing the following:
int t(char c) { return (int) c; }
...
if(!(t(d)>255)) { dostuff(); }
so i am interested in only ascii table representable chars, which i assume after conversion to int should be less than 256, am i right? thanks!
charis an integral type in C. You can do the check directly:I am assuming you don’t want to use
isascii()(it’s not in the C standard, although it is POSIX).Also, you can check if
CHAR_MAXis equal to 127. If it is, you don’t need the comparison with 127, sincecwill not exceed it by definition. Similarly, ifCHAR_MINis 0, then you don’t need the comparison with 0. BothCHAR_MINandCHAR_MAXare defined inlimits.h.I think you’re thinking about an integer value overflowing a
char, and therefore convert it to anint. But, that doesn’t help with overflow since the damage has already been done.