9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Mike Haertel <mike@ducky.net>
To: 9fans@cse.psu.edu
Subject: [9fans] compiler bug
Date: Wed, 11 Jul 2001 23:27:11 -0700	[thread overview]
Message-ID: <200107120627.f6C6RBh99881@ducky.net> (raw)

Under pcc, the following program:

	#include <stdio.h>
	#include <stdlib.h>

	int
	main()
	{
		printf("%d\n", (int) (0x80000000 >> 31));
		exit(EXIT_SUCCESS);
	}

prints -1.  It should print 1.  According to ANSI C (either version,
take your pick: c89, section 3.1.3.2, or c99, section 6.4.4.1) hex
and octal constants take on the first type in the list: int, unsigned
int, long, unsigned long, etc. in which their value is representable.

In this case, 0x80000000 is not a representable value of type int,
but is representable as unsigned int, so it should have that type.

This bit me today when some of the initializers of an "unsigned long long"
array mysteriously got sign extended from 32 bits.


             reply	other threads:[~2001-07-12  6:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-12  6:27 Mike Haertel [this message]
2001-07-12 10:21 ` Boyd Roberts
2001-07-12 10:33 forsyth
2001-07-12 13:19 forsyth
2001-07-14  5:39 David Gordon Hogan
2001-07-14  7:52 ` Mike Haertel
2014-05-30 13:03 [9fans] Compiler bug Julius Schmidt
2014-05-30 14:56 ` Charles Forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200107120627.f6C6RBh99881@ducky.net \
    --to=mike@ducky.net \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).