public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc interprets -0 incorrectly
@ 2002-12-06 15:12 Justin Pryzby
  2002-12-06 15:33 ` Zack Weinberg
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Justin Pryzby @ 2002-12-06 15:12 UTC (permalink / raw)
  To: gcc

/*
 * GCC interprets -0 as -INT_MIN==-INT_MAX - 1 (See <limits.h>).
 * It knows how to overflow from positive to negative,
 * and from negative to positive.
 *
 * However, I object to this interpretation,
 * even if it does allow an int to hold an extra number;
 * From algebra: it is clear that for all x=-x, 2x=0, x=0.
 * Also, for all x=0, 2x=0, x=-x.
 * That is, x=-x implies that x=0, AND x=0 implies that x=-x.
 *
 * Please CC: me in all replies, as I am not subscribed to the list.
 *
 * Justin
 */


#include <stdio.h>
#include <assert.h>

int main()
{
	int i=0;
	struct byte_struct {
		int a:1;
		int b:6;
		int c:1;
	} *byte;

	byte=(struct byte_struct *) (((char *) &i)+3);
	byte->c=1;

	// -2147483648
	printf("%d\n", i);

	// warning: this decimal constant is unsigned only in ISO C90.
	i=-2147483648;
	i--;
	printf("%d\n", i);

	i=2147483647;
	i++;
	printf("%d\n", i);

	return 0;
}

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

end of thread, other threads:[~2002-12-22 14:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-06 15:12 gcc interprets -0 incorrectly Justin Pryzby
2002-12-06 15:33 ` Zack Weinberg
2002-12-06 17:02 ` Neil Booth
2002-12-20  0:30 ` Segher Boessenkool
2002-12-22 20:04   ` Gaute B Strokkenes

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 read-only IMAP folder(s) and NNTP newsgroup(s).