Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Examples of current platforms/architectures where sizeof(void*) > sizeof(int*) ? Date: Wed, 01 Sep 2021 16:30:13 -0700 Organization: None to speak of Lines: 33 Message-ID: <87o89bho1m.fsf@nosuchdomain.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="4cfacb04df28b927d7c937dd51e9642b"; logging-data="7222"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7Poysd/vEq/IFH/9HerG7" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:xFN2Me3KmhkVprVv1sw54OPSbFQ= sha1:jdJF8VpVxCJQAuLskgAQdPzfEC4= Xref: csiph.com comp.lang.c++:81011 Bo Persson writes: > On 2021-09-01 at 20:34, Bonita Montero wrote: >> Am 01.09.2021 um 20:14 schrieb Juha Nieminen: >> >>> Thus, I wouldn't be surprised if malloc() (and new) always returns >>> a block that's aligned at a very minimum to the size of a pointer. >> malloc() returns a pointer which is aligned at least to max_align_t: >> https://en.cppreference.com/w/c/types/max_align_t > > Not entirely correct. The allocated storage must be properly aligned > for an object of that size. > > So if smaller than a long double, it can also be less aligned. That's not what the standard says: 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). It can be difficult to tell whether double *p = malloc(1); gives you proper alignment, but the standard doesn't give permission for small allocations to have less strict alignment. (BTW, there's no guarantee that long double has the strictest alignment.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips void Void(void) { Void(); } /* The recursive call of the void */