This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C PATCH] Disallow subtracting pointers to empty structs (PR c/58346)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>, Jason Merrill <jason at redhat dot com>
- Date: Wed, 15 Jan 2014 11:35:40 +0100
- Subject: Re: [C PATCH] Disallow subtracting pointers to empty structs (PR c/58346)
- Authentication-results: sourceware.org; auth=none
- References: <20140113163226 dot GD4458 at redhat dot com> <20140113164859 dot GE4458 at redhat dot com> <20140113204839 dot GF4458 at redhat dot com> <Pine dot LNX dot 4 dot 64 dot 1401142134140 dot 10324 at digraph dot polyomino dot org dot uk> <20140115102737 dot GJ4458 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Jan 15, 2014 at 11:27:37AM +0100, Marek Polacek wrote:
> Perhaps, but I don't think we can do it easily. Consider
>
> int
> foo (int *p, int *q)
> {
> return p - q;
> }
That is not a difference of pointers to zero sized arrays though,
that is pointers to int, and there is no division by zero involved, you can
get 0 as the result of course.
I think Joseph meant say
__PTRDIFF_TYPE__
foo (int p[3][0], int q[3][0])
{
return p - q;
}
which is also (((long int) p - (long int) q) /[ex] 0).
Jakub