Re: "array"

Liste des GroupesRevenir à cl c  
Sujet : Re: "array"
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 03. Apr 2025, 07:25:05
Autres entêtes
Organisation : None to speak of
Message-ID : <85iknllq2m.fsf@nosuchdomain.example.com>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13)
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
On 4/2/2025 6:31 PM, Keith Thompson wrote:
[...]
This is specified by the standard in the section describing memory
allocation functions.  In C17, it's in 7.22.3 paragraph 1 (which applies
to all of aligned_alloc, calloc, malloc, and realloc):
>
     The pointer returned if the allocation succeeds is suitably
     aligned so that it may be assigned to a pointer to any type of
     object with a fundamental alignment requirement and then used to
     access such an object or an array of such objects in the space
     allocated (until the space is explicitly deallocated).
>
The *effective type* rules are also relevant (section 6.5).
My reading of that section is that if you access malloc'ed memory
as an array, that memory has the array type as its effective type.
>
Iirc, aligned_alloc can only be used with types that are compatible
with the alignment. To use it with any object it must be a multiple of
max_align_t. What did I miss? Thanks.

A "fundamental alignment" is any alignment less than or equal
to _Alignof (max_align_t), which might be 8 bytes in a typical
implementation.  Some types may optionally require a stricter
"extended alignment".

My undertanding is that aligned_alloc is guaranteed to allocate
memory with at least a fundamental alignment, but will use a stricter
alignment if requested.  For example if _Alignof (max_align_t)
is 8, aligned_alloc(1, size) will still allocate at least 8-byte
aligned memory.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
2 Apr 25 * "array"9Stefan Ram
2 Apr 25 +* Re: "array"2Stefan Ram
2 Apr 25 i`- Re: "array"1Muttley
2 Apr 25 +- Re: "array"1Rosario19
3 Apr 25 +- Re: "array"1Tim Rentsch
3 Apr 25 `* Re: "array"4Keith Thompson
3 Apr 25  +* Re: "array"2Chris M. Thomasson
3 Apr 25  i`- Re: "array"1Keith Thompson
3 Apr 25  `- Re: "array"1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal