On Fri, 2007-04-13 at 15:20 +0100, Rhythmic Fistman wrote: > On 4/13/07, skaller <[EMAIL PROTECTED]> wrote: > > > Signed types don't support bitwise operations > > Why not?
The semantics are platform dependent in C: in C89 the semantics are indeterminate. The C90 standard has words that make it appear otherwise but the words weren't written by people that knew any maths .. they're total gibberish. In C99 its better, but representations are mow overconstrained, due to an idiot who didn't know any maths (or much about C) .. but still not enough for bitwise operations to be deterministic on signed values. Felix mandates (somewhere .. ) two's complement, so the operations would be deterministic, nevertheless I think it is very bad practice so it isn't supported in the library, deliberately. You can of course roll your own or argue to change the library: my choice is initial not terminal :) Roughly speaking signed integers are intended as local (close to 0) approximations to integers, and any other use is incorrect. Note the shift operators aren't bitwise operators, they're binary exponentials (this is true in C99 too). If you want to twiddle bits, unsigned values are both bit strings and also modular values: all the operations are total and platform independent (modulo the number of bits). > Or why does int -> uint require an explicit cast? Because ALL conversions in Felix require an explicit cast. Well actually this isn't quite true. 1. Lvalue -> rvalue decay is implicit 2. Function class -> closure is implicit So if you see: 1 + 2u working .. it isn't because of an implicit conversion, it's because there is an overload on + to support all combinations of integral addition. I actually don't like that, but it is quite necessary for binding libraries such as OpenGl which use crud like GLint which is an alias to some integer, but you don't know which one. if you want to set flags in signed values you can do: int$ (uint x \| 0xF) \& 0xF0 i.e. cast to unsigned, mess about, and cast back. If this is really too messy it can be fixed .. the closer we get to the mess C made, the less safety advantages Felix provides .. but compromises are necessary: binding C library code in a fairly convenient manner is essential. But there's usually more than one way to skin a cat .. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Felix-language mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/felix-language