-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalign.h
More file actions
67 lines (63 loc) · 2.4 KB
/
align.h
File metadata and controls
67 lines (63 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef __ALIGN_H__
#define __ALIGN_H__
/* Ensure that alignas, _Alignas, alignof, and _Alignof are not defined by previous includes */
#ifdef alignas
#undef alignas
#endif
#ifdef _Alignas
#undef _Alignas
#endif
#ifdef alignof
#undef alignof
#endif
#ifdef _Alignof
#undef _Alignof
#endif
/* Define alignas and _Alignas for all compilers and standards */
#if !defined(__cplusplus) || (__cplusplus < 201103L)
/* For C or C++ pre-C++11 */
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
/* GCC, Clang, and Intel Compiler use __attribute__ */
#define alignas(x) __attribute__((aligned(x)))
#define _Alignas alignas
#define alignof(type) __alignof__(type)
#define _Alignof alignof
#elif defined(_MSC_VER)
/* Microsoft Visual C++ uses __declspec */
#define alignas(x) __declspec(align(x))
#define _Alignas alignas
#warning "alignof and _Alignof are not directly supported by MSVC before C++11. Alignment queries will not work."
#define alignof(type)
#define _Alignof alignof
#else
/* For other compilers where alignment isn't supported, define as no-op */
#warning "This compiler does not support alignment features. alignas, _Alignas, alignof, and _Alignof are defined as no-ops."
#define alignas(x)
#define _Alignas
#define alignof(type)
#define _Alignof
#endif
#else
/* For C++11 and later */
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
/* For GCC, Clang, and Intel Compiler, use C++11's alignas and alignof unless explicitly overridden */
#define alignas(x) alignas(x)
#define _Alignas alignas
#define alignof(type) alignof(type)
#define _Alignof alignof
#elif defined(_MSC_VER)
/* MSVC supports alignas and alignof in C++11 mode */
#define alignas(x) alignas(x)
#define _Alignas alignas
#define alignof(type) alignof(type)
#define _Alignof alignof
#else
/* If the compiler doesn't support C++11 alignas or alignof, define as no-op */
#warning "This compiler does not support C++11 alignment features. alignas, _Alignas, alignof, and _Alignof are defined as no-ops."
#define alignas(x)
#define _Alignas
#define alignof(type)
#define _Alignof
#endif
#endif
#endif /* __ALIGN_H__ */