| OLD | NEW |
| 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 // This file contains macros and macro-like constructs (e.g., templates) that | 5 // This file contains macros and macro-like constructs (e.g., templates) that |
| 6 // are commonly used throughout Chromium source. (It may also contain things | 6 // are commonly used throughout Chromium source. (It may also contain things |
| 7 // that are closely related to things that are commonly used that belong in this | 7 // that are closely related to things that are commonly used that belong in this |
| 8 // file.) | 8 // file.) |
| 9 | 9 |
| 10 #ifndef BASE_MACROS_H_ | 10 #ifndef BASE_MACROS_H_ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // use its type. | 48 // use its type. |
| 49 template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; | 49 template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N]; |
| 50 #define arraysize(array) (sizeof(ArraySizeHelper(array))) | 50 #define arraysize(array) (sizeof(ArraySizeHelper(array))) |
| 51 | 51 |
| 52 // bit_cast<Dest,Source> is a template function that implements the | 52 // bit_cast<Dest,Source> is a template function that implements the |
| 53 // equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in | 53 // equivalent of "*reinterpret_cast<Dest*>(&source)". We need this in |
| 54 // very low-level functions like the protobuf library and fast math | 54 // very low-level functions like the protobuf library and fast math |
| 55 // support. | 55 // support. |
| 56 // | 56 // |
| 57 // float f = 3.14159265358979; | 57 // float f = 3.14159265358979; |
| 58 // int i = bit_cast<int32>(f); | 58 // int i = bit_cast<int32_t>(f); |
| 59 // // i = 0x40490fdb | 59 // // i = 0x40490fdb |
| 60 // | 60 // |
| 61 // The classical address-casting method is: | 61 // The classical address-casting method is: |
| 62 // | 62 // |
| 63 // // WRONG | 63 // // WRONG |
| 64 // float f = 3.14159265358979; // WRONG | 64 // float f = 3.14159265358979; // WRONG |
| 65 // int i = * reinterpret_cast<int*>(&f); // WRONG | 65 // int i = * reinterpret_cast<int*>(&f); // WRONG |
| 66 // | 66 // |
| 67 // The address-casting method actually produces undefined behavior | 67 // The address-casting method actually produces undefined behavior |
| 68 // according to ISO C++ specification section 3.10 -15 -. Roughly, this | 68 // according to ISO C++ specification section 3.10 -15 -. Roughly, this |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 // Use these to declare and define a static local variable (static T;) so that | 144 // Use these to declare and define a static local variable (static T;) so that |
| 145 // it is leaked so that its destructors are not called at exit. If you need | 145 // it is leaked so that its destructors are not called at exit. If you need |
| 146 // thread-safe initialization, use base/lazy_instance.h instead. | 146 // thread-safe initialization, use base/lazy_instance.h instead. |
| 147 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ | 147 #define CR_DEFINE_STATIC_LOCAL(type, name, arguments) \ |
| 148 static type& name = *new type arguments | 148 static type& name = *new type arguments |
| 149 | 149 |
| 150 } // base | 150 } // base |
| 151 | 151 |
| 152 #endif // BASE_MACROS_H_ | 152 #endif // BASE_MACROS_H_ |
| OLD | NEW |