… | |
… | |
465 | |
465 | |
466 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
466 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
467 | ecb_inline unsigned char |
467 | ecb_inline unsigned char |
468 | ecb_byteorder_helper (void) |
468 | ecb_byteorder_helper (void) |
469 | { |
469 | { |
470 | const uint32_t u = 0x11223344; |
470 | /* the union code still generates code under pressure in gcc, */ |
471 | return *(unsigned char *)&u; |
471 | /* but less than using pointers, and always seem to */ |
|
|
472 | /* successfully return a constant. */ |
|
|
473 | /* the reason why we have this horrible preprocessor mess */ |
|
|
474 | /* is to avoid it in all cases, at leats on common architectures */ |
|
|
475 | #if __i386 || __i386__ || _M_X86 || __amd64 || __amd64__ || _M_X64 |
|
|
476 | return 0x44; |
|
|
477 | #elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
|
|
478 | return 0x44; |
|
|
479 | #elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
|
|
480 | retrurn 0x11; |
|
|
481 | #else |
|
|
482 | union |
|
|
483 | { |
|
|
484 | uint32_t i; |
|
|
485 | uint8_t c; |
|
|
486 | } u = { 0x11223344 }; |
|
|
487 | return u.c; |
|
|
488 | #endif |
472 | } |
489 | } |
473 | |
490 | |
474 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
491 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
475 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
492 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
476 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
493 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |