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

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

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 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 unified diff | Download patch
« no previous file with comments | « mojo/public/c/system/functions.h ('k') | mojo/public/c/system/main.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_C_SYSTEM_MACROS_H_
6 #define MOJO_PUBLIC_C_SYSTEM_MACROS_H_
7
8 #include <stddef.h>
9
10 // Annotate a variable indicating it's okay if it's unused.
11 // Use like:
12 // int x = ...;
13 // MOJO_ALLOW_UNUSED_LOCAL(x);
14 #define MOJO_ALLOW_UNUSED_LOCAL(x) false ? (void)x : (void)0
15
16 // Annotate a function indicating that the caller must examine the return value.
17 // Use like:
18 // int foo() MOJO_WARN_UNUSED_RESULT;
19 // Note that it can only be used on the prototype, and not the definition.
20 #if defined(__GNUC__)
21 #define MOJO_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
22 #else
23 #define MOJO_WARN_UNUSED_RESULT
24 #endif
25
26 #ifdef __cplusplus
27 // Used to explicitly mark the return value of a function as unused. If you are
28 // really sure you don't want to do anything with the return value of a function
29 // that has been marked WARN_UNUSED_RESULT, wrap it with this. Example:
30 //
31 // scoped_ptr<MyType> my_var = ...;
32 // if (TakeOwnership(my_var.get()) == SUCCESS)
33 // mojo_ignore_result(my_var.release());
34 //
35 template <typename T>
36 inline void mojo_ignore_result(const T&) {
37 }
38 #endif
39
40 // Assert things at compile time. (|msg| should be a valid identifier name.)
41 // This macro is currently C++-only, but we want to use it in the C core.h.
42 // Use like:
43 // MOJO_STATIC_ASSERT(sizeof(Foo) == 12, "Foo has invalid size");
44 #if defined(__cplusplus)
45 #define MOJO_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
46 #else
47 #define MOJO_STATIC_ASSERT(expr, msg)
48 #endif
49
50 // Like the C++11 |alignof| operator.
51 #if __cplusplus >= 201103L
52 #define MOJO_ALIGNOF(type) alignof(type)
53 #elif defined(__GNUC__)
54 #define MOJO_ALIGNOF(type) __alignof__(type)
55 #elif defined(_MSC_VER)
56 // The use of |sizeof| is to work around a bug in MSVC 2010 (see
57 // http://goo.gl/isH0C; supposedly fixed since then).
58 #define MOJO_ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type))
59 #else
60 #error "Please define MOJO_ALIGNOF() for your compiler."
61 #endif
62
63 // Specify the alignment of a |struct|, etc.
64 // Use like:
65 // struct MOJO_ALIGNAS(8) Foo { ... };
66 // Unlike the C++11 |alignas()|, |alignment| must be an integer. It may not be a
67 // type, nor can it be an expression like |MOJO_ALIGNOF(type)| (due to the
68 // non-C++11 MSVS version).
69 #if __cplusplus >= 201103L
70 #define MOJO_ALIGNAS(alignment) alignas(alignment)
71 #elif defined(__GNUC__)
72 #define MOJO_ALIGNAS(alignment) __attribute__((aligned(alignment)))
73 #elif defined(_MSC_VER)
74 #define MOJO_ALIGNAS(alignment) __declspec(align(alignment))
75 #else
76 #error "Please define MOJO_ALIGNAS() for your compiler."
77 #endif
78
79 #endif // MOJO_PUBLIC_C_SYSTEM_MACROS_H_
OLDNEW
« no previous file with comments | « mojo/public/c/system/functions.h ('k') | mojo/public/c/system/main.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698