[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pointer addition and arrays
From: |
Bruno Haible |
Subject: |
Re: pointer addition and arrays |
Date: |
Sun, 03 Dec 2023 11:03:30 +0100 |
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
> referenced type, the behaviour is undefined.
>
> alignof(char) will be 1 and the alignment of foo will probably be 4, hence
> there is no guarantee that the pointer value of p is properly aligned.
There is no guarantee, but the malloc() result has an alignment of at least 4
on all of today's platforms. [1]
Bruno
[1] see gnulib/lib/memalign.c and gnulib/m4/malloc-align.m4.
- Re: undefined-behavior obstack.c:139, (continued)
- Re: undefined-behavior obstack.c:139, Paul Eggert, 2023/12/14
- Re: undefined-behavior obstack.c:139, Bruno Haible, 2023/12/16
- Re: undefined-behavior obstack.c:139, Paul Eggert, 2023/12/17
- Re: undefined-behavior obstack.c:139, Bruno Haible, 2023/12/18
- Re: undefined-behavior obstack.c:139, Paul Eggert, 2023/12/21
- Re: undefined-behavior obstack.c:139, Andreas F. Borchert, 2023/12/01
- Re: undefined-behavior obstack.c:139, Bruno Haible, 2023/12/02
- Re: undefined-behavior obstack.c:139, Andreas F. Borchert, 2023/12/02
- Re: pointer addition and arrays, Bruno Haible, 2023/12/03
- Re: pointer addition and arrays, Andreas F. Borchert, 2023/12/03
- Re: pointer addition and arrays,
Bruno Haible <=
- Re: pointer addition and arrays, Andreas F. Borchert, 2023/12/03
- Re: pointer addition and arrays, Paul Eggert, 2023/12/14
- Re: pointer addition and arrays, Marc Nieper-Wißkirchen, 2023/12/16
- Re: pointer addition and arrays, Paul Eggert, 2023/12/17
- Re: pointer addition and arrays, Marc Nieper-Wißkirchen, 2023/12/17