| Deutsch English Français Italiano |
|
<85iknllq2m.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: "array"
Date: Wed, 02 Apr 2025 23:25:05 -0700
Organization: None to speak of
Lines: 35
Message-ID: <85iknllq2m.fsf@nosuchdomain.example.com>
References: <array-20250402114422@ram.dialup.fu-berlin.de>
<85a58y58ul.fsf@nosuchdomain.example.com>
<vsl51b$3pr14$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 03 Apr 2025 08:25:06 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="658736fab9029f452335cecd036b8387";
logging-data="4119661"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z2XHKXHaJ1ms2mc/yE/j5"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:e6gLvZLVpGPmdnZM1KLw8K1MdvE=
sha1:m55Yc1AgWMjEGGFXTc7OclLjqxE=
Bytes: 2692
"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 */