Denis Vlasenko writes: > On Tuesday 19 December 2006 20:05, Andrew Haley wrote: > > Denis Vlasenko writes: > > > > > > I wrote this just a few days ago: > > > > > > do { > > > int32_t v1 = v << 1; > > > if (v < 0) v1 ^= mask; > > > v = v1; > > > printf("%10u: %08x\n", c++, v); > > > } while (v != 1); > > > > > > I would become rather sad if this will stop compiling correctly. > > > > I can understand the objections to do with "dusty deck" code that > > hasn't been looked at for aeons, but in the case of code that you > > wrote so recently, given that you understand the issue, why not simply > > use the standard idiom? > > I want sane compiler. > One in which N-bit integer variables stay exactly N-bit. > Without "magic" N+1 bit which is there "somethimes". a*2/2: > If I say "multiply by 2 and _after that_ divide by 2, > I meant that. Compiler can optimize it any way it wants, > as long as result is the same as unoptimized one.
This kind of thinking was appropriate before standardization. But C changed. C is no longer a kind of high-level assembly laguage: it's defined by a standard, in terms of an abstract machine, and some operations are not well-defined. If you want your programs to do what you expect, you'd better find out what that abstract machine does. > Above: v is a signed entity. I expect (v < 0) to be equal to > "most significant bit is set". It's not about standards. > It's about sanity. You'd better find some other programming langauge that is defined the way you want. Andrew.