This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C PATCH] Disallow subtracting pointers to empty structs (PR c/58346)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]