Hi Kjetil,

On Dienstag, 7. Januar 2025 14:00:16 MEZ Kjetil Oftedal wrote:
> How can the compiler in this case assume that endptr and str do not
> point to the same array object?
> 
> ISO C99 6.5,8  Relational operators
> 5)
> ...
> "If the expression P points to an element of an array object and the
> expression Q points to the last element of the same array object,
> the pointer expression Q+1 compares greater than P. In all other
> cases, the behavior is undefined"
> 
> How does the compiler at compile time know that endptr which is
> equivalent is to str[maxlen] is not within the
> range of string declared by str?
> Or in the terms of the above standard, how does it know that endptr is not 
> Q+1?
>
> [...]

The compiler does not need to know!

Let's consider the pointer 'x', the offset 'offs' and

  y = x + offset

with y < x (because offset is huge).

So if y < (x + offset) then y points to a different object by definition.
Hence, the compiler is allowed to remove this test.

Frank
-- 
Dr.-Ing. Frank Mehnert, [email protected], +49-351-41 883 224

Kernkonzept GmbH.  Sitz: Dresden.  Amtsgericht Dresden, HRB 31129.
Geschäftsführer: Dr.-Ing. Michael Hohmuth


_______________________________________________
devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to