9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] 8c puzzling behavior
@ 2011-03-08 17:16 erik quanstrom
  2011-03-08 20:21 ` geoff at plan9.bell-labs.com
  2011-03-08 23:32 ` Bakul Shah
  0 siblings, 2 replies; 8+ messages in thread
From: erik quanstrom @ 2011-03-08 17:16 UTC (permalink / raw)


for this

	uvlong u, i;

	i = 31;
	u = 0xff00000000000000ull;

i get

	u & 1<<i		-> 0xff00000000000000ull
	u & 0x80000000		-> 0
	u & (int)0x80000000	-> 0xff00000000000000ull
	u & -2147483648		-> 0

to put a finer point on it,

	(uvlong)(1<<i)		-> 0xffffffff80000000
	(uvlong)(0x80000000)	-> 0x80000000
	(uvlong)(int)0x80000000	-> 0xffffffff80000000
	(uvlong)-2147483648	-> 0x80000000

so it seems clear that constants are treated as if unsigned, regardless,
but variables are not?

can this be correct?  i hate to hazzard guesses about the c standard.

- erik



^ permalink raw reply	[flat|nested] 8+ messages in thread
* [9fans] 8c puzzling behavior
@ 2011-03-08 17:21 erik quanstrom
  2011-03-08 17:43 ` Lucio De Re
  0 siblings, 1 reply; 8+ messages in thread
From: erik quanstrom @ 2011-03-08 17:21 UTC (permalink / raw)


> so it seems clear that constants are treated as if unsigned, regardless,
> but variables are not?

the really wierd bit is that the 1 in 1<<i suddenly becomes signed,
even though other constants are treated as if unsigned, and i is
unsigned.

- erik



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-09 13:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 17:16 [9fans] 8c puzzling behavior erik quanstrom
2011-03-08 20:21 ` geoff at plan9.bell-labs.com
2011-03-08 23:32 ` Bakul Shah
2011-03-08 23:54   ` erik quanstrom
2011-03-09  7:23     ` Charles Forsyth
2011-03-09 13:05       ` erik quanstrom
2011-03-08 17:21 erik quanstrom
2011-03-08 17:43 ` Lucio De Re

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).