From: Neil Booth <neil@daikokuya.co.uk>
To: Al Viro <viro@ftp.linux.org.uk>
Cc: linux-sparse@vger.kernel.org
Subject: Re: pointer arithmetics and casts
Date: Sat, 26 May 2007 12:44:09 +0900 [thread overview]
Message-ID: <20070526034409.GO2547@daikokuya.co.uk> (raw)
In-Reply-To: <20070525212300.GL4095@ftp.linux.org.uk>
Al Viro wrote:-
> But that means a fsckload of extra nodes allocated on pretty much any
> program - use of arrays is not rare and indices tend to be int, so we
> hit an extra allocated node on each such place.
>
> Another possible solution is to add a primitive for combined conversion
> and multiplication - basically, convert the first argument to the type of
> the second one and multiply. We would actually need it only for ptrdiff_t;
> sizeof(*p) is going to fit into the range anyway (it has to - the difference
> between (char *)(p+1) and (char *)p must fit into it, or we couldn't do any
> arithmetics on that pointer type at all; as soon as product overflows
> ptrdiff_t we are free to do whatever the hell we like, since that's an
> undefined behaviour and "multiply as ptrdiff_t values" gives an reasonable
> result even in such cases).
Perhaps not overloading the "+" node; reserve that for arithmetic types.
Have a ptr_add, (maybe) ptr_sub, and ptr_diff operations.
GCC's moved to having at least a ptr_add recently.
Neil.
next prev parent reply other threads:[~2007-05-26 3:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-25 21:23 pointer arithmetics and casts Al Viro
2007-05-25 22:00 ` Al Viro
2007-05-26 15:45 ` Al Viro
2007-05-26 1:14 ` Morten Welinder
2007-05-26 3:32 ` Derek M Jones
2007-05-26 4:16 ` Al Viro
2007-05-26 3:43 ` Al Viro
2007-05-26 3:44 ` Neil Booth [this message]
2007-05-26 4:22 ` Al Viro
2007-05-26 4:37 ` Neil Booth
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=20070526034409.GO2547@daikokuya.co.uk \
--to=neil@daikokuya.co.uk \
--cc=linux-sparse@vger.kernel.org \
--cc=viro@ftp.linux.org.uk \
/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