Re: pointer addition and arrays

2023-12-17 Thread Marc Nieper-Wißkirchen
Am So., 17. Dez. 2023 um 09:50 Uhr schrieb Paul Eggert : > On 2023-12-16 04:42, Marc Nieper-Wißkirchen wrote: > > the problem is if further down in the compiler pipeline, the > > P <= P expression produces some intermediate code that becomes equal to > > code the optimizer should rightfully optimi

Re: pointer addition and arrays

2023-12-17 Thread Paul Eggert
On 2023-12-16 04:42, Marc Nieper-Wißkirchen wrote: the problem is if further down in the compiler pipeline, the P <= P expression produces some intermediate code that becomes equal to code the optimizer should rightfully optimize away I'm skeptical that such optimizations would be worth the tro

Re: pointer addition and arrays

2023-12-16 Thread Marc Nieper-Wißkirchen
Am Fr., 15. Dez. 2023 um 02:00 Uhr schrieb Paul Eggert : > On 12/3/23 05:15, Andreas F. Borchert wrote: > > You will have > > then to possibly live with annoying warnings and odd behaviours. > > The C standard says that when P is a null pointer, P==P must be true > whereas P<=P has undefined behav

Re: pointer addition and arrays

2023-12-14 Thread Paul Eggert
On 12/3/23 05:15, Andreas F. Borchert wrote: You will have then to possibly live with annoying warnings and odd behaviours. The C standard says that when P is a null pointer, P==P must be true whereas P<=P has undefined behavior. However, in practice any implementation where P==P succeeds but

Re: pointer addition and arrays

2023-12-03 Thread Andreas F. Borchert
On Sun, Dec 03, 2023 at 11:03:30AM +0100, Bruno Haible wrote: > There is no guarantee, but the malloc() result has an alignment of at least 4 > on all of today's platforms. [1] It may be legitimate to have such assumptions. But it is likewise legitimate that compilers and the associated libraries

Re: pointer addition and arrays

2023-12-03 Thread Bruno Haible
Andreas F. Borchert wrote: > > foo *p = (foo *) m; /* CAST */ > ... > This line is not guaranteed to be ok due to § 6.3.2.3, (7): > >A pointer to an object type may be converted to a pointer to a different >object type. If the resulting pointer is not correctly aligned for the >r

Re: pointer addition and arrays

2023-12-03 Thread Andreas F. Borchert
> foo.c > > #include > #include > #ifdef __GNUC__ > # define unreachable() __builtin_unreachable () > #endif > typedef struct { int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t; } foo; > int main () > { > char *m = malloc (1)

Re: pointer addition and arrays

2023-12-02 Thread Bruno Haible
Andreas F. Borchert wrote: > > I still don't know whether it's OK to have pointers to arrays with > > 0 elements (which are not "array objects", since "objects" are non- > > empty (§ 6.2.6.1.(2))). > > From § 6.7.6.2 about array declarators: > >If the expression is a constant expression, it s