Re: Pointers in comparison expressions

2005-07-25 Thread Geoff Keating
On 23/07/2005, at 6:12 PM, Paul Schlie wrote: Geoffrey Keating wrote: Mirco Lorenzon wrote: .., are comparisons in the following program legal code? No. ... void *a, *b; ... if (a < b) Because 'a' and 'b' are not part of the same array, the behaviour is undefined. Although I don'

Re: Pointers in comparison expressions

2005-07-23 Thread Paul Schlie
> Geoffrey Keating wrote: >> Mirco Lorenzon wrote: >> >> .., are comparisons in the following program legal code? > > No. > >> ... >> void *a, *b; >> ... >> if (a < b) > > Because 'a' and 'b' are not part of the same array, > the behaviour is undefined. Although I don't mean to contest the conclu

Re: Pointers in comparison expressions

2005-07-22 Thread Geoffrey Keating
Mirco Lorenzoni <[EMAIL PROTECTED]> writes: > Can a pointer appear in a C/C++ relational expression which doesn't test the > equality (or the inequality) of that pointer with respect to another pointer? Yes. > For example, are the comparisons in the following program legal code? No. > /* test

Re: Pointers in comparison expressions

2005-07-18 Thread Paul Koning
> "D" == D Hugh Redelmeier <[EMAIL PROTECTED]> writes: D> This is true. And an abomination. But I will explain a bit more D> where this came from. ... Thanks Doug. "Abomination" is a good word for it. paul

Re: Pointers in comparison expressions

2005-07-18 Thread Paul Koning
> "Vincent" == Vincent Lefevre <[EMAIL PROTECTED]> writes: Vincent> On 2005-07-17 12:55:38 -0400, Paul Koning wrote: >> Are you sayinvg that a-b is not always "guaranteed to work" when a >> and b point to elements of the same array? That sounds wrong; can >> you given an example or standar

Re: Pointers in comparison expressions

2005-07-17 Thread D. Hugh Redelmeier
| From: Vincent Lefevre <[EMAIL PROTECTED]> | To: gcc@gcc.gnu.org | Subject: Re: Pointers in comparison expressions | | On 2005-07-17 12:55:38 -0400, Paul Koning wrote: | > Are you sayinvg that a-b is not always "guaranteed to work" when a | > and b point to elements o

Re: Pointers in comparison expressions

2005-07-17 Thread Vincent Lefevre
On 2005-07-17 12:55:38 -0400, Paul Koning wrote: > Are you sayinvg that a-b is not always "guaranteed to work" when a > and b point to elements of the same array? That sounds wrong; can > you given an example or standards text that supports this? 6.5.6 Additive operators [...] [#9]

Re: Pointers in comparison expressions

2005-07-17 Thread Paul Koning
> "Vincent" == Vincent Lefevre <[EMAIL PROTECTED]> writes: Vincent> On 2005-07-12 23:42:23 +0200, Erik Trulsson wrote: >> Pointer subtraction is only well defined if both pointers point to >> elements in the same array (or one past the end of the array). Vincent> I don't know what you mea

Re: Pointers in comparison expressions

2005-07-16 Thread Vincent Lefevre
On 2005-07-12 23:42:23 +0200, Erik Trulsson wrote: > Pointer subtraction is only well defined if both pointers point to > elements in the same array (or one past the end of the array). I don't know what you mean by "well defined", but even in this case, the behavior can be undefined. So, replacing

Re: Pointers in comparison expressions

2005-07-13 Thread Olivier Galibert
On Wed, Jul 13, 2005 at 01:28:14AM +0200, Falk Hueffner wrote: > You're missing my point; size_t was just an example, whoever does this > will know what the correct type is for their system. All I'm saying > is that we shouldn't go to the trouble to document and kick along some > language extensio

Re: Pointers in comparison expressions

2005-07-13 Thread Morten Welinder
> Relational tests between pointers is only allowed by > the ISO C standard if the two pointers point into the > same array, or if a pointer points to exactly one byte > beyond the array. There actually is a way to compare arbitrary data pointers within the C standards: you send the pointers throu

Re: Pointers in comparison expressions

2005-07-12 Thread Joe Buck
On Wed, Jul 13, 2005 at 01:28:14AM +0200, Falk Hueffner wrote: > Joe Buck <[EMAIL PROTECTED]> writes: > > If you want to be pedantic, that's not portable; in particular, it > > will break for some of the memory models used with 16-bit Windows > > You're missing my point; size_t was just an example

Re: Pointers in comparison expressions

2005-07-12 Thread Falk Hueffner
Joe Buck <[EMAIL PROTECTED]> writes: > On Wed, Jul 13, 2005 at 12:38:11AM +0200, Falk Hueffner wrote: >> Erik Trulsson <[EMAIL PROTECTED]> writes: >> > I believe most C compilers support it in practice, but few, if any, have >> > actually documented it as a supported extension to C. >> >> I don't

Re: Pointers in comparison expressions

2005-07-12 Thread Michael Meissner
On Wed, Jul 13, 2005 at 12:38:11AM +0200, Falk Hueffner wrote: > Erik Trulsson <[EMAIL PROTECTED]> writes: > > > On Tue, Jul 12, 2005 at 03:08:54PM -0700, Joe Buck wrote: > >> On Tue, Jul 12, 2005 at 11:42:23PM +0200, Erik Trulsson wrote: > >> > Pointer subtraction is only well defined if both poi

Re: Pointers in comparison expressions

2005-07-12 Thread Michael Meissner
On Tue, Jul 12, 2005 at 06:25:45PM +0200, Mirco Lorenzoni wrote: > Can a pointer appear in a C/C++ relational expression which doesn't test the > equality (or the inequality) of that pointer with respect to another pointer? > For example, are the comparisons in the following program legal code? >

Re: Pointers in comparison expressions

2005-07-12 Thread Joe Buck
On Wed, Jul 13, 2005 at 12:38:11AM +0200, Falk Hueffner wrote: > Erik Trulsson <[EMAIL PROTECTED]> writes: > > I believe most C compilers support it in practice, but few, if any, have > > actually documented it as a supported extension to C. > > I don't think we should, either. People who want to

Re: Pointers in comparison expressions

2005-07-12 Thread Joe Buck
On Wed, Jul 13, 2005 at 12:28:47AM +0200, Erik Trulsson wrote: > On Tue, Jul 12, 2005 at 03:08:54PM -0700, Joe Buck wrote: > > On Tue, Jul 12, 2005 at 11:42:23PM +0200, Erik Trulsson wrote: > > > Pointer subtraction is only well defined if both pointers point to > > > elements > > > in the same ar

Re: Pointers in comparison expressions

2005-07-12 Thread Falk Hueffner
Erik Trulsson <[EMAIL PROTECTED]> writes: > On Tue, Jul 12, 2005 at 03:08:54PM -0700, Joe Buck wrote: >> On Tue, Jul 12, 2005 at 11:42:23PM +0200, Erik Trulsson wrote: >> > Pointer subtraction is only well defined if both pointers point to elements >> > in the same array (or one past the end of th

Re: Pointers in comparison expressions

2005-07-12 Thread Erik Trulsson
On Tue, Jul 12, 2005 at 03:08:54PM -0700, Joe Buck wrote: > On Tue, Jul 12, 2005 at 11:42:23PM +0200, Erik Trulsson wrote: > > Pointer subtraction is only well defined if both pointers point to elements > > in the same array (or one past the end of the array). Otherwise the > > behaviour is undefi

Re: Pointers in comparison expressions

2005-07-12 Thread Joe Buck
On Tue, Jul 12, 2005 at 11:42:23PM +0200, Erik Trulsson wrote: > Pointer subtraction is only well defined if both pointers point to elements > in the same array (or one past the end of the array). Otherwise the > behaviour is undefined. While this is correct, there are certain cases that the stan

Re: Pointers in comparison expressions

2005-07-12 Thread Erik Trulsson
On Tue, Jul 12, 2005 at 05:54:00PM +0100, Dave Korn wrote: > Original Message > >From: Daniel Berlin > >Sent: 12 July 2005 17:33 > > >> I think that even if the use of relational operators other than '==' and > >> '!=' is legal with pointers, the compiler should issue a warning (when > >>

Re: Pointers in comparison expressions

2005-07-12 Thread Andreas Schwab
"Dave Korn" <[EMAIL PROTECTED]> writes: > Since pointer subtraction is well defined, and it returns an int, then ... > > int *a, *b; > > if (a < b) > dosomething (); > > ... is just the same as ... > > int *a, *b; > > if ((b - a) >= 0) > dosomething (); This may not work correctly i

Re: Pointers in comparison expressions

2005-07-12 Thread chris jefferson
Mirco Lorenzoni wrote: >Can a pointer appear in a C/C++ relational expression which doesn't test the >equality (or the inequality) of that pointer with respect to another pointer? >For example, are the comparisons in the following program legal code? > >/* test.c */ >#include > >int main(int ar

RE: Pointers in comparison expressions

2005-07-12 Thread Dave Korn
Original Message >From: Daniel Berlin >Sent: 12 July 2005 17:33 >> I think that even if the use of relational operators other than '==' and >> '!=' is legal with pointers, the compiler should issue a warning (when >> the option -Wall is used), as it does for assignment, used as truth >> va

Re: Pointers in comparison expressions

2005-07-12 Thread Daniel Berlin
> I think that even if the use of relational operators other than '==' and '!=' > is legal with pointers, the compiler should issue a warning (when the option > -Wall is used), as it does for assignment, used as truth values, not > surrounded with parentheses. Why? It's legal, it's useful, and