This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/2] Use C11 _Alignas on scratch_buffer internal buffer
On 19/09/2017 10:29, Andreas Schwab wrote:
> On Sep 19 2017, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
>
>> diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h
>> index bb04662..0f49dd9 100644
>> --- a/include/scratch_buffer.h
>> +++ b/include/scratch_buffer.h
>> @@ -66,7 +66,7 @@
>> struct scratch_buffer {
>> void *data; /* Pointer to the beginning of the scratch area. */
>> size_t length; /* Allocated space at the data pointer, in bytes. */
>> - max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)];
>> + union { max_align_t __a; char __c[1024]; } __space;
>
> If you make it an anonymous union you don't even need to change the rest
> of the code.
>
> Andreas.
>
Something like below maybe?
---
* include/scratch_buffer.h (scratch_buffer): Use an union instead
of a max_align_t array for __space definition.
---
diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h
index bb04662..cc394a7 100644
--- a/include/scratch_buffer.h
+++ b/include/scratch_buffer.h
@@ -66,7 +66,7 @@
struct scratch_buffer {
void *data; /* Pointer to the beginning of the scratch area. */
size_t length; /* Allocated space at the data pointer, in bytes. */
- max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)];
+ union { max_align_t __align; char __space[1024]; };
};
/* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space