thanx for the answer, but I didn't understand why "long x = 0xFFFF"
produces -1
It doesn't.
a long is 32 bit even on 16-bit systems, isn't it? so you get 65535
anyway
However 0xFFFF doesn't have long type, it has type int of that can
represent 65535 or else unsigned int which is guaranteed to be able to
represent 65535. In either case the value is then converted to long before
being assigned.
So the code does do the right thing i.e. x ends up with the value 65535,
always. But there are types other than long involved. However
long x = 0x10000;
STILL works find and is guaranteed to give x the value 65536. If the value
can't be represented as an unsigned int the compiler will represent it as
a long. However there are cases where you need to force to a longer type,
e.g. the expression
1 << 24
i.e. 1 left shifted 24 places is invalid on systems with, say, 16 bit
ints. Whereas
1L << 24
and for many cases
1UL << 24
is even better because bit manipulations are best done on unsigned types.
Lawrence