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

Andreas Schwab schwab@linux-m68k.org
Mon Sep 18 17:06:00 GMT 2017


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."



More information about the Libc-alpha mailing list