Commit graph

10 commits

Author SHA1 Message Date
carl 5f9a199257 CPP ISO C90 compatibility and conversion. 2019-03-02 01:44:16 +08:00
George Koehler 59b3c10563 Use (arith) 1 << ... when getting the sign bit.
This prevents an overflow reported by @hexcoder- in
https://github.com/davidgiven/ack/issues/56

lang/cem/cpp.ansi/LLlex.c used a plain 1 << ... and caused an overflow
on machines where sizeof(int) < sizeof(long).  Using 1L << ... would
work for now but might fail later if arith became long long.

C doesn't specify whether negative integers use 2's complement or some
other format.  Therefore, (arith) 1 << ... has an undefined value.  It
should still work because the value is some integer where the sign bit
is set and all other bits are clear.

(unsigned arith) 1 << ... would also get the sign bit, but casting it
from unsigned back to signed would make the same undefined value.

(arith) -1 << ... would assume 2's complement.
2017-10-29 17:45:10 -04:00
George Koehler 1ab1306baa Always use unsigned long in lang/cem
Same reason as commit 649410b.
2017-10-29 17:01:29 -04:00
ceriel f069cba449 Made arith_sign more portable 1995-03-28 09:10:31 +00:00
ceriel 86cb2d66d7 Fixed: % and / were interchanged 1995-03-27 11:46:47 +00:00
ceriel 1db6a3029b Header --> Id 1994-06-24 14:02:31 +00:00
ceriel 6fc94eb375 Improved constant arithmetic: had several bugs 1993-03-18 13:24:20 +00:00
eck 6e551adf21 fixed some more bugs 1989-11-03 10:36:56 +00:00
eck 741b43044d renamed ch7xxx to ch3xxx 1989-10-23 13:00:35 +00:00
eck 1d37165575 Initial revision 1989-10-23 10:35:56 +00:00