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

Side by Side Diff: mojo/public/c/system/macros.h

Issue 295383012: Mojo: Require our public options structs to be aligned like int64_t's. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win 2 Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/public/c/system/data_pipe.h ('k') | mojo/public/c/system/tests/macros_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_ 5 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_
6 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_ 6 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 // Annotate a variable indicating it's okay if it's unused. 10 // Annotate a variable indicating it's okay if it's unused.
11 // Use like: 11 // Use like:
12 // int x MOJO_ALLOW_UNUSED = ...; 12 // int x MOJO_ALLOW_UNUSED = ...;
13 #if defined(__GNUC__) 13 #if defined(__GNUC__)
14 #define MOJO_ALLOW_UNUSED __attribute__((unused)) 14 #define MOJO_ALLOW_UNUSED __attribute__((unused))
15 #else 15 #else
16 #define MOJO_ALLOW_UNUSED 16 #define MOJO_ALLOW_UNUSED
17 #endif 17 #endif
18 18
19 // Annotate a function indicating that the caller must examine the return value. 19 // Annotate a function indicating that the caller must examine the return value.
20 // Use like: 20 // Use like:
21 // int foo() MOJO_WARN_UNUSED_RESULT; 21 // int foo() MOJO_WARN_UNUSED_RESULT;
22 // Note that it can only be used on the prototype, and not the definition. 22 // Note that it can only be used on the prototype, and not the definition.
23 #if defined(__GNUC__) 23 #if defined(__GNUC__)
24 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 24 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
25 #else 25 #else
26 #define MOJO_WARN_UNUSED_RESULT 26 #define MOJO_WARN_UNUSED_RESULT
27 #endif 27 #endif
28 28
29 // Assert things at compile time. (|msg| should be a valid identifier name.)
29 // This macro is currently C++-only, but we want to use it in the C core.h. 30 // This macro is currently C++-only, but we want to use it in the C core.h.
30 // Used to assert things at compile time. 31 // Use like:
32 // MOJO_COMPILE_ASSERT(sizeof(Foo) == 12, Foo_has_invalid_size);
31 #if __cplusplus >= 201103L 33 #if __cplusplus >= 201103L
32 #define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) 34 #define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
33 #elif defined(__cplusplus) 35 #elif defined(__cplusplus)
34 namespace mojo { template <bool> struct CompileAssert {}; } 36 namespace mojo { template <bool> struct CompileAssert {}; }
35 #define MOJO_COMPILE_ASSERT(expr, msg) \ 37 #define MOJO_COMPILE_ASSERT(expr, msg) \
36 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] 38 typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
37 #else 39 #else
38 #define MOJO_COMPILE_ASSERT(expr, msg) 40 #define MOJO_COMPILE_ASSERT(expr, msg)
39 #endif 41 #endif
40 42
43 // Like the C++11 |alignof| operator.
44 #if __cplusplus >= 201103L
45 #define MOJO_ALIGNOF(type) alignof(type)
46 #elif defined(__GNUC__)
47 #define MOJO_ALIGNOF(type) __alignof__(type)
48 #elif defined(_MSC_VER)
49 // The use of |sizeof| is to work around a bug in MSVC 2010 (see
50 // http://goo.gl/isH0C; supposedly fixed since then).
51 #define MOJO_ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
52 #else
53 #error "Please define MOJO_ALIGNOF() for your compiler."
54 #endif
55
56 // Specify the alignment of a |struct|, etc.
57 // Use like:
58 // struct MOJO_ALIGNAS(8) Foo { ... };
59 // Unlike the C++11 |alignas()|, |alignment| must be an integer. It may not be a
60 // type, nor can it be an expression like |MOJO_ALIGNOF(type)| (due to the
61 // non-C++11 MSVS version).
62 #if __cplusplus >= 201103L
63 #define MOJO_ALIGNAS(alignment) alignas(alignment)
64 #elif defined(__GNUC__)
65 #define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment)))
66 #elif defined(_MSC_VER)
67 #define MOJO_ALIGNAS(alignment) __declspec(align(alignment))
68 #else
69 #error "Please define MOJO_ALIGNAS() for your compiler."
70 #endif
71
41 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_ 72 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_
OLDNEW
« no previous file with comments | « mojo/public/c/system/data_pipe.h ('k') | mojo/public/c/system/tests/macros_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698