This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] Use C11 _Alignas on scratch_buffer internal buffer


On Sep 18 2017, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:

> diff --git a/include/scratch_buffer.h b/include/scratch_buffer.h
> index bb04662..2e0c8b5 100644
> --- a/include/scratch_buffer.h
> +++ b/include/scratch_buffer.h
> @@ -60,13 +60,18 @@
>  #include <stdbool.h>
>  #include <stddef.h>
>  #include <stdlib.h>
> +#include <stdalign.h>
>  
>  /* Scratch buffer.  Must be initialized with scratch_buffer_init
>     before its use.  */
>  struct scratch_buffer {
>    void *data;    /* Pointer to the beginning of the scratch area.  */
>    size_t length; /* Allocated space at the data pointer, in bytes.  */
> +#if __alignas_is_defined
> +  _Alignas (max_align_t) char __space[1024];
> +#else
>    max_align_t __space[(1023 + sizeof (max_align_t)) / sizeof (max_align_t)];
> +#endif

You could use a union instead.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]