OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 // There is an additional use for BitCast. | 281 // There is an additional use for BitCast. |
282 // Recent gccs will warn when they see casts that may result in breakage due to | 282 // Recent gccs will warn when they see casts that may result in breakage due to |
283 // the type-based aliasing rule. If you have checked that there is no break age | 283 // the type-based aliasing rule. If you have checked that there is no break age |
284 // you can use BitCast to cast one pointer type to another. This confuses g cc | 284 // you can use BitCast to cast one pointer type to another. This confuses g cc |
285 // enough that it can no longer see that you have cast one pointer type to | 285 // enough that it can no longer see that you have cast one pointer type to |
286 // another thus avoiding the warning. | 286 // another thus avoiding the warning. |
287 template <class Dest, class Source> | 287 template <class Dest, class Source> |
288 inline Dest BitCast(const Source& source) { | 288 inline Dest BitCast(const Source& source) { |
289 // Compile time assertion: sizeof(Dest) == sizeof(Source) | 289 // Compile time assertion: sizeof(Dest) == sizeof(Source) |
290 // A compile error here means your Dest and Source have different sizes. | 290 // A compile error here means your Dest and Source have different sizes. |
291 COMPILE_ASSERT(sizeof(Dest) == sizeof(Source), VerifySizesAreEqual); | 291 static_assert(sizeof(Dest) == sizeof(Source), "Verify sizes are equal"); |
Nico
2014/12/16 17:56:28
"sizes should be equal" would be more similar to t
Mostyn Bramley-Moore
2014/12/16 19:00:37
Done.
| |
292 | 292 |
293 Dest dest; | 293 Dest dest; |
294 memcpy(&dest, &source, sizeof(dest)); | 294 memcpy(&dest, &source, sizeof(dest)); |
295 return dest; | 295 return dest; |
296 } | 296 } |
297 | 297 |
298 template <class Dest, class Source> | 298 template <class Dest, class Source> |
299 inline Dest BitCast(Source* source) { | 299 inline Dest BitCast(Source* source) { |
300 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source)); | 300 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source)); |
301 } | 301 } |
302 | 302 |
303 } // namespace double_conversion | 303 } // namespace double_conversion |
304 | 304 |
305 } // namespace WTF | 305 } // namespace WTF |
306 | 306 |
307 #endif // DOUBLE_CONVERSION_UTILS_H_ | 307 #endif // DOUBLE_CONVERSION_UTILS_H_ |
OLD | NEW |