vsh@pixdoc.UUCP (Steve Harris) (03/27/86)
There is a bug in the putc macro, in stdio.h. Putc returns an int which contains the char you have just "put". However, (at least on both a Pixel and a Sun), the result is sign extended; if the 8th bit of the char is set, the return value from putc does not equal the character you put! To fix, replace the putc macro with the following: #define putc(x,p) ((int) ((--(p)->_cnt>=0? ((unsigned char)(*(p)->_ptr++=(x))):(unsigned char)_flsbuf((x),p)))) -- Steve Harris | {allegra|ihnp4|cbosgd|ima|genrad|amd|harvard}\ xePIX, Inc. | !wjh12!pixel!pixdoc!vsh 51 Lake Street | Nashua, NH 03060 | +1 603 881 8791
bzs@bu-cs.UUCP (Barry Shein) (03/28/86)
>There is a bug in the putc macro, in stdio.h. >Putc returns an int which contains the char you have just "put". >However, (at least on both a Pixel and a Sun), the result is sign extended; >if the 8th bit of the char is set, the return value from putc does not equal >the character you put! To fix, replace the putc macro with the following: > >#define putc(x,p) ((int) ((--(p)->_cnt>=0? ((unsigned char)(*(p)->_ptr++=(x))):(unsigned char)_flsbuf((x),p)))) > >Steve Harris WRONG Putc (actually _flsbuf()) can return EOF which on my SUN* is defined as (-1). Doing the above would cause the return value to become 0xff and would not test negative. I believe (uh oh) that what you want here is to change the (unsigned char)s to (unsigned int)s, your timing is off as to when you want it to happen. I tried it on a SUN and it properly returns 0xff for 0xff and -1 for -1. Someone here suggested that it was too bad that EOF was not defined as some negative value like 0xffff0000 (ie. < -255) which is a nice thought but it's too late I suppose, it would have thus been even more out of band (not easily confused with sign-extended 0xff.) -Barry Shein, Boston University