Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2516)

Unified Diff: base/compiler_specific.h

Issue 9186057: Add ALIGNAS and ALIGNOF macros to ensure proper alignment of StaticMemorySingletonTraits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win compile Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/memory/singleton.h » ('j') | base/memory/singleton.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/compiler_specific.h
diff --git a/base/compiler_specific.h b/base/compiler_specific.h
index 0a6e05a6c67988b64b416b612d47ec41c457a78f..c47362a4e55c6932acfefa3277a19244b648afed 100644
--- a/base/compiler_specific.h
+++ b/base/compiler_specific.h
@@ -96,6 +96,25 @@
#define NOINLINE
#endif
+// Specify memory alignment for structs, classes or data.
+// Use like:
+// class ALIGNED(16) MyClass { ... }
+// int array[4] ALIGNED(16);
+#if defined(COMPILER_MSVC)
+#define ALIGNED(byte_alignment) __declspec(align(byte_alignment))
Sigurður Ásgeirsson 2012/01/13 14:32:18 MSVS wants __declspec to precede the declarator, w
jbates 2012/01/13 17:29:18 At least for struct and class, I think GCC allows
+#elif defined(COMPILER_GCC)
+#define ALIGNED(byte_alignment) __attribute__((aligned(byte_alignment)))
+#endif
+
+// Return the byte alignment of the given type (available at compile time).
+// Use like:
+// ALIGNOF(int32) // this would be 4
+#if defined(COMPILER_MSVC)
+#define ALIGNOF(type) __alignof(type)
+#elif defined(COMPILER_GCC)
+#define ALIGNOF(type) __alignof__(type)
+#endif
+
// Annotate a virtual method indicating it must be overriding a virtual
// method in the parent class.
// Use like:
« no previous file with comments | « no previous file | base/memory/singleton.h » ('j') | base/memory/singleton.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698