Puzzle on unsigned promotions
Stephen J. Friedl
friedl at vsi.UUCP
Thu Jun 30 03:41:14 AEST 1988
Hi net.C.wizards,
Can any of you help with a puzzle? I've been trying to
understand the unsigned- vs value-perserving rules of various C
compilers, and I'm afraid I've run into a case I don't
understand. I have pored over the dpANS plus Chris Torek's notes
on this but am still confused. Note that this question applies
to all compilers, not just dsANSI ones, so this discussion is not
in comp.std.c.
/*
* what is printed?
*/
#define MINUS_ONE 0xffff
main()
{
unsigned short sval;
long lval1, lval2;
sval = MINUS_ONE;
lval1 = - sval;
lval2 = - (unsigned short) MINUS_ONE;
printf("lval #1 = %ld #2 = %ld\n", lval1, lval2);
}
The normal answer I get is:
lval #1 = -65535 #2 = -65535
but on the HP9000 I see:
lval #1 = 1 #2 = -65535
For what it's worth, the HP9000 has sizeof(short) = 2 and
sizeof(int) = 4, and I get the same results when I #define
MINUS_ONE to be (-1) or 0xffff.
My specific questions:
(1) is this a case of questionable unsigned-ness?
(2) if I have a vendor who asserts "this is a value-preserving
compiler", what is the necessary value of "lval"?
(3) if I have a vendor who asserts "this is a unsigned-preserving
compiler", what is the necessary value of "lval"?
(4) if I have a vendor who asserts "this is a dpANS-conformant"
compiler", what is the necessary value of "lval"? [OK, OK,
they're not supposed to assert that yet, but you know what
I mean here]
(5) how about them Lakers? :-)
Thanks for your help. Please email, I'll summarize and post.
Steve
--
Steve Friedl V-Systems, Inc. (714) 545-6442 3B2-kind-of-guy
friedl at vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl
Nancy Reagan on John DeLorean: "Just say snow"
More information about the Comp.lang.c
mailing list