C++ Logo

std-proposals

Advanced search

Re: [std-proposals] operator alignof

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sun, 1 May 2022 12:34:00 +0200
On 01/05/2022 10.22, Abdullah Qasim via Std-Proposals wrote:
>
>
> Consider:
>
>
>
> class cstring {
>
> // assume public functions...
>
>
>
> private:
>
> char* ptr; // used for dynamic allocation
>
> uint64_t length;
>
> }
>
>
>
> Now, assume I make cstring c(“12”)
>
>
>
> Length takes 8 bytes.
>
> Allocated char array takes 3 bytes.
>
> Therefore:
>
> alignof(c)
>
> returns 8
>
>
>
> Why not 3?:
>
>
>
> // In cstring
>
> operator alignof () {
>
> return alignof (charArr);
>
> }
>
>
>
> Which is what the user expected!

Are you confusing sizeof and alignof?
Why would alignof(charArr) ever return 3?

Jens

Received on 2022-05-01 10:34:05