This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 2/2] Use C11 _Alignas on scratch_buffer internal buffer
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Mon, 18 Sep 2017 11:42:54 -0300
- Subject: [PATCH 2/2] Use C11 _Alignas on scratch_buffer internal buffer
- Authentication-results: sourceware.org; auth=none
- References: <1505745774-29303-1-git-send-email-adhemerval.zanella@linaro.org>
Checked on x86_64-linux-gnu.
* include/scratch_buffer.h (scratch_buffer): Use C11 _Alignas on
__space field definition if compiler supports it.
---
ChangeLog | 3 +++
include/scratch_buffer.h | 5 +++++
2 files changed, 8 insertions(+)
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
};
/* Initializes *BUFFER so that BUFFER->data points to BUFFER->__space
--
2.7.4