OLD | NEW |
1 // Copyright 2008 The Chromium Authors. All rights reserved. | 1 // Copyright 2008 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 MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_ | 5 #ifndef MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_ |
6 #define MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_ | 6 #define MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(COMPILER_MSVC) | 10 #if defined(COMPILER_MSVC) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Specify memory alignment for structs, classes, etc. | 49 // Specify memory alignment for structs, classes, etc. |
50 // Use like: | 50 // Use like: |
51 // class ALIGNAS(16) MyClass { ... } | 51 // class ALIGNAS(16) MyClass { ... } |
52 // ALIGNAS(16) int array[4]; | 52 // ALIGNAS(16) int array[4]; |
53 #if defined(COMPILER_MSVC) | 53 #if defined(COMPILER_MSVC) |
54 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) | 54 #define ALIGNAS(byte_alignment) __declspec(align(byte_alignment)) |
55 #elif defined(COMPILER_GCC) | 55 #elif defined(COMPILER_GCC) |
56 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) | 56 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment))) |
57 #endif | 57 #endif |
58 | 58 |
| 59 // Return the byte alignment of the given type (available at compile time). Use |
| 60 // sizeof(type) prior to checking __alignof to workaround Visual C++ bug: |
| 61 // http://goo.gl/isH0C |
| 62 // Use like: |
| 63 // ALIGNOF(int32_t) // this would be 4 |
| 64 #if defined(COMPILER_MSVC) |
| 65 #define ALIGNOF(type) (sizeof(type) - sizeof(type) + __alignof(type)) |
| 66 #elif defined(COMPILER_GCC) |
| 67 #define ALIGNOF(type) __alignof__(type) |
| 68 #endif |
| 69 |
59 #if defined(COMPILER_MSVC) | 70 #if defined(COMPILER_MSVC) |
60 #define WARN_UNUSED_RESULT | 71 #define WARN_UNUSED_RESULT |
61 #else | 72 #else |
62 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) | 73 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
63 #endif | 74 #endif |
64 | 75 |
65 #if defined(COMPILER_MSVC) | 76 #if defined(COMPILER_MSVC) |
66 #define PRINTF_FORMAT(format_param, dots_param) | 77 #define PRINTF_FORMAT(format_param, dots_param) |
67 #else | 78 #else |
68 #define PRINTF_FORMAT(format_param, dots_param) \ | 79 #define PRINTF_FORMAT(format_param, dots_param) \ |
69 __attribute__((format(printf, format_param, dots_param))) | 80 __attribute__((format(printf, format_param, dots_param))) |
70 #endif | 81 #endif |
71 | 82 |
72 #endif // MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_ | 83 #endif // MINI_CHROMIUM_BASE_COMPILER_SPECIFIC_H_ |
OLD | NEW |