From: "Dave Korn" <dk@artimi.com>
To: "'Joe Buck'" <Joe.Buck@synopsys.COM>
Cc: "'Andreas Schwab'" <schwab@suse.de>,
"'Morten Welinder'" <terra@gnome.org>, <gcc@gcc.gnu.org>
Subject: RE: signed vs unsigned pointer warning
Date: Thu, 23 Sep 2004 19:38:00 -0000 [thread overview]
Message-ID: <NUTMEGJg3jQNjcW2nmW00000073@NUTMEG.CAM.ARTIMI.COM> (raw)
In-Reply-To: <20040923091118.A2943@synopsys.com>
> -----Original Message-----
> From: Joe Buck [mailto:Joe.Buck@synopsys.COM]
> Sent: 23 September 2004 17:11
> On Thu, Sep 23, 2004 at 12:35:22PM +0100, Dave Korn wrote:
> > > "Dave Korn" writes:
> > >
> > > > Which I don't think you can, since you can't store
> negative numbers
> > > > in an unsigned type.
> > >
> > > Actually you can, due to the modulo behaviour of unsigned
> integers.
> > >
> > > Andreas.
> >
> > Well, yes, it is physically possible, but it's a kind of
> type-punning, it
> > defies the aliasing rules, and we get into some very deeply
> > language-lawyerly issues here, but it's not a valid
> representation IIUIC and
> > therefore invokes undefined behaviour in many circumstances.
>
> The C aliasing rules specifically bless accessing ints as
> unsigneds, and,
> more generally, punning accesses between any type and the
> unsigned version
> of that type.
Ya learn something new every day :)
Actually, come to think of it, I stumbled across that myself just a few
weeks back, when I was trying to work round the _restrict_ bug (in a block
of code that was copying some memory to some registers) by defining one
pointer as an int and one pointer as a long (both actually being 32 bit
ints), and I had tried to use the signed/unsigned distinction to get it to
work, but it didn't until I actually used different underlying types.
Anyway, it's all wandering a bit far enough from the original point now,
which is that a warning would be a good idea, and I'm convinced enough by
that line of argument without any reference to the finer details of buggy
ctype implementations anyway!
cheers,
DaveK
--
Can't think of a witty .sigline today....
next prev parent reply other threads:[~2004-09-23 16:31 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-22 16:43 Morten Welinder
2004-09-22 17:17 ` Paul Koning
2004-09-22 17:27 ` Morten Welinder
2004-09-22 17:49 ` Dave Korn
2004-09-22 17:20 ` Dave Korn
2004-09-23 1:31 ` Andreas Schwab
2004-09-23 12:29 ` Dave Korn
2004-09-23 18:57 ` Joe Buck
2004-09-23 19:38 ` Dave Korn [this message]
2004-09-27 2:04 ` Jamie Lokier
2004-10-08 13:29 ` Nick Ing-Simmons
2004-10-08 13:32 ` Dave Korn
2004-10-08 17:20 ` Joe Buck
2004-10-08 17:28 ` Paul Jarc
2004-10-08 17:59 ` Joe Buck
2004-10-08 18:15 ` Dave Korn
2004-10-08 18:22 ` Joe Buck
2004-10-08 18:24 ` Jamie Lokier
2004-10-08 19:57 ` Paul Jarc
2004-10-09 7:05 ` Jamie Lokier
2004-10-09 8:48 ` Paul Jarc
2004-10-11 16:34 ` Richard Earnshaw
2004-10-08 18:57 ` Morten Welinder
2004-10-08 20:59 ` Matthias B.
2004-10-08 22:34 ` Paul Koning
2004-10-10 2:03 ` Matthias B.
2004-10-09 1:39 ` Andreas Schwab
2004-10-11 0:11 ` Kai Henningsen
-- strict thread matches above, loose matches on Subject: below --
2004-09-21 20:52 Richard Henderson
2004-09-21 22:36 ` Linus Torvalds
2004-09-22 14:35 ` Dave Korn
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=NUTMEGJg3jQNjcW2nmW00000073@NUTMEG.CAM.ARTIMI.COM \
--to=dk@artimi.com \
--cc=Joe.Buck@synopsys.COM \
--cc=gcc@gcc.gnu.org \
--cc=schwab@suse.de \
--cc=terra@gnome.org \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).