Changeset 46689 in vbox for trunk/include/iprt
- Timestamp:
- Jun 19, 2013 7:55:58 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/assert.h
r43363 r46689 298 298 #ifdef __GNUC__ 299 299 # define AssertCompileNS(expr) extern int RTASSERTVAR[1] __attribute__((unused)), RTASSERTVAR[(expr) ? 1 : 0] __attribute__((unused)) 300 #elif defined(__IBMC__) || defined(__IBMCPP__) 301 # define AssertCompileNS(expr) extern int RTASSERTVAR[(expr) ? 1 : 0] 300 302 #else 301 303 # define AssertCompileNS(expr) typedef int RTASSERTTYPE[(expr) ? 1 : 0] … … 312 314 # define AssertCompile(expr) AssertCompileNS(expr) 313 315 #endif 316 317 /** @def RTASSERT_OFFSET_OF() 318 * A offsetof() macro suitable for compile time assertions. 319 * Both GCC v4 and VisualAge for C++ v3.08 has trouble using RT_OFFSETOF. 320 */ 321 #if defined(__GNUC__) 322 # if __GNUC__ >= 4 323 # define RTASSERT_OFFSET_OF(a_Type, a_Member) __builtin_offsetof(a_Type, a_Member) 324 # else 325 # define RTASSERT_OFFSET_OF(a_Type, a_Member) RT_OFFSETOF(a_Type, a_Member) 326 # endif 327 #elif (defined(__IBMC__) || defined(__IBMCPP__)) && defined(RT_OS_OS2) 328 # define RTASSERT_OFFSET_OF(a_Type, a_Member) __offsetof(a_Type, a_Member) 329 #else 330 # define RTASSERT_OFFSET_OF(a_Type, a_Member) RT_OFFSETOF(a_Type, a_Member) 331 #endif 332 314 333 315 334 /** @def AssertCompileSize … … 353 372 * @param align The member offset alignment to assert. 354 373 */ 355 #if defined(__GNUC__) 356 # if __GNUC__ >= 4 357 # define AssertCompileMemberAlignment(type, member, align) \ 358 AssertCompile(!(__builtin_offsetof(type, member) & ((align) - 1))) 359 # else 360 # define AssertCompileMemberAlignment(type, member, align) \ 361 AssertCompile(!(RT_OFFSETOF(type, member) & ((align) - 1))) 362 # endif 363 #else 364 # define AssertCompileMemberAlignment(type, member, align) \ 365 AssertCompile(!(RT_OFFSETOF(type, member) & ((align) - 1))) 366 #endif 374 #define AssertCompileMemberAlignment(type, member, align) \ 375 AssertCompile(!(RTASSERT_OFFSET_OF(type, member) & ((align) - 1))) 367 376 368 377 /** @def AssertCompileMemberOffset … … 372 381 * @param off The expected offset. 373 382 */ 374 #if defined(__GNUC__) 375 # if __GNUC__ >= 4 376 # define AssertCompileMemberOffset(type, member, off) \ 377 AssertCompile(__builtin_offsetof(type, member) == (off)) 378 # else 379 # define AssertCompileMemberOffset(type, member, off) \ 380 AssertCompile(RT_OFFSETOF(type, member) == (off)) 381 # endif 382 #else 383 # define AssertCompileMemberOffset(type, member, off) \ 384 AssertCompile(RT_OFFSETOF(type, member) == (off)) 385 #endif 383 #define AssertCompileMemberOffset(type, member, off) \ 384 AssertCompile(RTASSERT_OFFSET_OF(type, member) == (off)) 386 385 387 386 /** @def AssertCompile2MemberOffsets … … 391 390 * @param member2 The second member. 392 391 */ 393 #if defined(__GNUC__) 394 # if __GNUC__ >= 4 395 # define AssertCompile2MemberOffsets(type, member1, member2) \ 396 AssertCompile(__builtin_offsetof(type, member1) == __builtin_offsetof(type, member2)) 397 # else 398 # define AssertCompile2MemberOffsets(type, member1, member2) \ 399 AssertCompile(RT_OFFSETOF(type, member1) == RT_OFFSETOF(type, member2)) 400 # endif 401 #else 402 # define AssertCompile2MemberOffsets(type, member1, member2) \ 403 AssertCompile(RT_OFFSETOF(type, member1) == RT_OFFSETOF(type, member2)) 404 #endif 392 #define AssertCompile2MemberOffsets(type, member1, member2) \ 393 AssertCompile(RTASSERT_OFFSET_OF(type, member1) == RTASSERT_OFFSET_OF(type, member2)) 405 394 406 395 /** @def AssertCompileAdjacentMembers … … 410 399 * @param member2 The second member. 411 400 */ 412 #if defined(__GNUC__) 413 # if __GNUC__ >= 4 414 # define AssertCompileAdjacentMembers(type, member1, member2) \ 415 AssertCompile(__builtin_offsetof(type, member1) + RT_SIZEOFMEMB(type, member1) == __builtin_offsetof(type, member2)) 416 # else 417 # define AssertCompileAdjacentMembers(type, member1, member2) \ 418 AssertCompile(RT_OFFSETOF(type, member1) + RT_SIZEOFMEMB(type, member1) == RT_OFFSETOF(type, member2)) 419 # endif 420 #else 421 # define AssertCompileAdjacentMembers(type, member1, member2) \ 422 AssertCompile(RT_OFFSETOF(type, member1) + RT_SIZEOFMEMB(type, member1) == RT_OFFSETOF(type, member2)) 423 #endif 401 #define AssertCompileAdjacentMembers(type, member1, member2) \ 402 AssertCompile(RTASSERT_OFFSET_OF(type, member1) + RT_SIZEOFMEMB(type, member1) == RTASSERT_OFFSET_OF(type, member2)) 424 403 425 404 /** @def AssertCompileMembersAtSameOffset … … 430 409 * @param member2 The second member. 431 410 */ 432 #if defined(__GNUC__) 433 # if __GNUC__ >= 4 434 # define AssertCompileMembersAtSameOffset(type1, member1, type2, member2) \ 435 AssertCompile(__builtin_offsetof(type1, member1) == __builtin_offsetof(type2, member2)) 436 # else 437 # define AssertCompileMembersAtSameOffset(type1, member1, type2, member2) \ 438 AssertCompile(RT_OFFSETOF(type1, member1) == RT_OFFSETOF(type2, member2)) 439 # endif 440 #else 441 # define AssertCompileMembersAtSameOffset(type1, member1, type2, member2) \ 442 AssertCompile(RT_OFFSETOF(type1, member1) == RT_OFFSETOF(type2, member2)) 443 #endif 444 411 #define AssertCompileMembersAtSameOffset(type1, member1, type2, member2) \ 412 AssertCompile(RTASSERT_OFFSET_OF(type1, member1) == RTASSERT_OFFSET_OF(type2, member2)) 413 445 414 /** @def AssertCompileMembersSameSize 446 415 * Asserts that members of two different structures have the same size. … … 461 430 * @param member2 The second member. 462 431 */ 463 #if defined(__GNUC__) 464 # if __GNUC__ >= 4 465 # define AssertCompileMembersSameSizeAndOffset(type1, member1, type2, member2) \ 466 AssertCompile(__builtin_offsetof(type1, member1) == __builtin_offsetof(type2, member2) && RT_SIZEOFMEMB(type1, member1) == RT_SIZEOFMEMB(type2, member2)) 467 # else 468 # define AssertCompileMembersSameSizeAndOffset(type1, member1, type2, member2) \ 469 AssertCompile(RT_OFFSETOF(type1, member1) == RT_OFFSETOF(type2, member2) && RT_SIZEOFMEMB(type1, member1) == RT_SIZEOFMEMB(type2, member2)) 470 # endif 471 #else 472 # define AssertCompileMembersSameSizeAndOffset(type1, member1, type2, member2) \ 473 AssertCompile(RT_OFFSETOF(type1, member1) == RT_OFFSETOF(type2, member2) && RT_SIZEOFMEMB(type1, member1) == RT_SIZEOFMEMB(type2, member2)) 474 #endif 432 #define AssertCompileMembersSameSizeAndOffset(type1, member1, type2, member2) \ 433 AssertCompile( RTASSERT_OFFSET_OF(type1, member1) == RTASSERT_OFFSET_OF(type2, member2) \ 434 && RT_SIZEOFMEMB(type1, member1) == RT_SIZEOFMEMB(type2, member2)) 475 435 476 436 /** @} */
Note:
See TracChangeset
for help on using the changeset viewer.