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'
> 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
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
> "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
> "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
| 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
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]
> "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
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
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
> 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
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
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
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
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?
>
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
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
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
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
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
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
> >>
"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
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
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
> 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
25 matches
Mail list logo