[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SCM_PTR_LE ?
From: |
Mr. Peter Ivanyi |
Subject: |
Re: SCM_PTR_LE ? |
Date: |
Thu, 01 Aug 2002 18:09:59 +0100 |
Marius Vollmer wrote:
> What is that definition? I think ANSI C only defines the outcome of
> comparisons for pointers that point into the same object, i.e., the
> same array or a single block returned from malloc. A consequence
> would be that you can not reliably test whether a pointer does point
> into some object, since the results are not defined when it points
> outside. For example, is the following guaranteed to print "sane"?
>
> char block1[100];
> char block2[100];
>
> char *ptr = block1 + 50;
>
> if (ptr >= block2 && ptr < block2+100)
> printf ("sane\n");
> else
> printf ("insane\n");
>
> I don't know.
Well, some of the memory checker programs would definitely signal an error
for the above code. As I remember, ANSI defines, that if a pointer goes
out of its range, then it becomes undefined. This have the unfortunate
consequence that
block2+2000-1990
is not valid, you have to calculate the offset first, than use it with the
pointer. On the positive side though, I have never seen, heard any compiler
which takes this as a problem, only memory checker.
Hope it helps a little bit.
Peter Ivanyi