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
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.c */
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 standards text that
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-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 mean by well
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]
| 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 of the same array? That sounds
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 a
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 through
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 extension,
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 stdio.h
int main(int argc, char* argv[])
{
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
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
values, not
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 stdio.h
int main(int
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 if ((char*) b -
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
the option
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
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 undefined.
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 the array).
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 array (or one
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 do this
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:
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
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 think we
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,
25 matches
Mail list logo