Bug list for Microsoft C

Guy Harris guy at gorodish.Sun.COM
Thu Jul 21 15:16:03 AEST 1988


> +>main() {
> +>    printf("%x\n", 1<<33);
> +>    printf("%x\n", 1>>33);
> +>    printf("%x\n", i<<j);
> +>    printf("%x\n", i>>j);
> +>}
> +>What results do you get?
> +>oh boy, I just checked a non 86, and it failed too.)
> +
> +Under Xenix '386, I get: 2, 0, 2, 0; using the '286 compiler, I get 0, 0, 2,
> +0.  So, anybody, what does ANSI say (in plain English)?  I tried reading the
> +draft to see what it should be, and I couldn't make head nor tail of it...
> +Somebody said, earlier, that both K&R and ANSI say the results are
> +implementation defined, but, from what I could stand of the draft, it didn't
> +seem to say that.

Yes, both the current ANSI C draft and K&R say the result is undefined (not
even implementation-defined).  K&R:

	7.5 Shift operators

	...

	The result is undefined if the right operand is negative, or greater
	than or equal to the length of the object in bits.

ANSI C:

	3.3.7 Bitwise shift operators

	...If the value of the right operand is negative or is greater than or
	equal to the width in bits of the promoted left operand, the behavior
	is undefined.

> Something of a letdown, that.  So what ARE the right numbers, and what is the
> right answer?

There aren't any, and there isn't one.  Next question.



More information about the Comp.lang.c mailing list