Re: alignas (C11)

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: alignas (C11)
Date: 2025-11-18 13:35:59
Message-ID: 70913dbd-dadf-4560-9f81-c0df72bf6578@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12.11.25 15:27, Chao Li wrote:
> 0002 simplifies several structures/unions by using alignas, I have a couple of minor comment:
>
> 1 - 0002
> ```
> -typedef union PGAlignedBlock
> +typedef struct PGAlignedBlock
> {
> - char data[BLCKSZ];
> - double force_align_d;
> - int64 force_align_i64;
> + alignas(MAXIMUM_ALIGNOF) char data[BLCKSZ];
> } PGAlignedBlock;
> ```
>
> As we changes PGAlignedBlock from union to structure, I think we can explicitly mention in the commit message something like “PGAlignedBlock has the same alignment and contiguous array data, thus no ABI change”.

We don't care about ABI changes in major releases.

> 2 - 0002
> ```
> - /* page_buffer must be adequately aligned, so use a union */
> - union
> - {
> - char buf[QUEUE_PAGESIZE];
> - AsyncQueueEntry align;
> - } page_buffer;
> + /* page_buffer must be adequately aligned */
> + alignas(AsyncQueueEntry) char page_buffer[QUEUE_PAGESIZE];
> ```
>
> To make readers easier to understand the statement, maybe we can explicitly use alignof:
>
> alignas(alignof(AsyncQueueEntry)) char page_buffer[QUEUE_PAGESIZE];

I don't know. alignas(type) is standard C and seems pretty intuitive to
me. Writing it the long way would be potentially more confusing IMO.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Roman Khapov 2025-11-18 13:51:18 *_LAST in enums to define NUM* macross
Previous Message Peter Eisentraut 2025-11-18 13:31:10 Re: Confused static assertion implementation