Ruby  3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
stdalign.h
Go to the documentation of this file.
1 #ifndef RBIMPL_STDALIGN_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_STDALIGN_H
23 #include "ruby/internal/config.h"
24 
25 #ifdef STDC_HEADERS
26 # include <stddef.h>
27 #endif
28 
33 
53 #if defined(__cplusplus) && RBIMPL_HAS_FEATURE(cxx_alignas)
54 # define RBIMPL_ALIGNAS alignas
55 
56 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
57 # define RBIMPL_ALIGNAS alignas
58 
59 #elif defined(__INTEL_CXX11_MODE__)
60 # define RBIMPL_ALIGNAS alignas
61 
62 #elif defined(__GXX_EXPERIMENTAL_CXX0X__)
63 # define RBIMPL_ALIGNAS alignas
64 
65 #elif RBIMPL_HAS_DECLSPEC_ATTRIBUTE(align)
66 # define RBIMPL_ALIGNAS(_) __declspec(align(_))
67 
68 #elif RBIMPL_HAS_ATTRIBUTE(aligned)
69 # define RBIMPL_ALIGNAS(_) __attribute__((__aligned__(_)))
70 
71 #else
72 # define RBIMPL_ALIGNAS(_) /* void */
73 #endif
74 
86 #if defined(__DOXYGEN__)
87 # define RBIMPL_ALIGNOF alignof
88 #elif defined(__cplusplus)
89 # /* C++11 `alignof()` can be buggy. */
90 # /* see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69560 */
91 # /* But don't worry, we can use templates. */
92 # define RBIMPL_ALIGNOF(T) (static_cast<size_t>(ruby::rbimpl_alignof<T>::value))
93 
94 namespace ruby {
95 template<typename T>
96 struct rbimpl_alignof {
97  typedef struct {
98  char _;
99  T t;
100  } type;
101 
102  enum {
103  value = offsetof(type, t)
104  };
105 };
106 }
107 
108 #elif RBIMPL_COMPILER_IS(MSVC)
109 # /* Windows have no alignment glitch.*/
110 # define RBIMPL_ALIGNOF __alignof
111 
112 #elif defined(HAVE__ALIGNOF)
113 # /* Autoconf detected availability of a sane `_Alignof()`. */
114 # define RBIMPL_ALIGNOF(T) RB_GNUC_EXTENSION(_Alignof(T))
115 
116 #else
117 # /* :BEWARE: This is the last resort. If your compiler somehow supports
118 # * querying the alignment of a type, you definitely should use that instead.
119 # * There are 2 known pitfalls for this fallback implementation:
120 # *
121 # * First, it is either an undefined behaviour (C) or an explicit error (C++)
122 # * to define a struct inside of `offsetof`. C compilers tend to accept such
123 # * things, but AFAIK C++ has no room to allow.
124 # *
125 # * Second, there exist T such that `struct { char _; T t; }` is invalid. A
126 # * known example is when T is a struct with a flexible array member. Such
127 # * struct cannot be enclosed into another one.
128 # */
129 # /* see: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2083.htm */
130 # /* see: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm */
131 # define RBIMPL_ALIGNOF(T) offsetof(struct { char _; T t; }, t)
132 
133 #endif
134 
135 #endif /* RBIMPL_STDALIGN_H */
Defines RBIMPL_HAS_ATTRIBUTE.
Defines RBIMPL_COMPILER_IS.
Defines RBIMPL_HAS_DECLSPEC_ATTRIBUTE.
Defines RBIMPL_HAS_FEATURE.
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
The main namespace.
Definition: cxxanyargs.hpp:37
#define _(args)
This was a transition path from K&R to ANSI.
Definition: stdarg.h:35