1 // endian_test.cpp ---------------------------------------------------------//
3 // Copyright Beman Dawes 1999-2008
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // See library home page at http://www.boost.org/libs/endian
10 //----------------------------------------------------------------------------//
12 // This test probes for correct endianess, size, and value.
14 // See endian_operations_test for tests of operator correctness and interaction
15 // between operand types.
17 //----------------------------------------------------------------------------//
19 #include <boost/integer/endian.hpp>
20 #include <boost/cstdint.hpp>
21 #include <boost/progress.hpp>
26 #include <cstdlib> // for atoi(), exit()
27 #include <cstring> // for memcmp()
29 using namespace std
; // Not the best programming practice, but I
30 using namespace boost
; // want to verify this combination of using
31 using namespace boost::integer
; // namespaces works. See endian_operations_test
32 // // for tests that don't do "using namespace".
34 #define VERIFY(predicate) verify( predicate, __LINE__ )
35 #define VERIFY_SIZE(actual, expected) verify_size( actual, expected, __LINE__ )
36 #define VERIFY_VALUE_AND_OPS(endian_t,expected_t,expected) verify_value_and_ops<endian_t, expected_t>( expected, __LINE__ )
37 #define VERIFY_BIG_REPRESENTATION(t) verify_representation<t>( true, __LINE__ )
38 #define VERIFY_LITTLE_REPRESENTATION(t) verify_representation<t>( false, __LINE__ )
39 #define VERIFY_NATIVE_REPRESENTATION(t) verify_native_representation<t>( __LINE__ )
45 void verify( bool x
, int line
)
49 cout
<< "Error: verify failed on line " << line
<< endl
;
52 void verify_size( size_t actual
, size_t expected
, int line
)
54 if ( actual
== expected
) return;
56 cout
<< "Error: verify size failed on line " << line
<< endl
;
57 cout
<< " A structure with an expected sizeof() " << expected
58 << " had an actual sizeof() " << actual
59 << "\n This will cause common uses of <boost/endian.hpp> to fail\n";
62 template <class Endian
, class Base
>
63 void verify_value_and_ops( const Base
& expected
, int line
)
66 verify( v
== expected
, line
);
69 v2
.operator=( expected
);
70 verify( v2
== expected
, line
);
72 ++v
; // verify integer_cover_operators being applied to this type -
73 // will fail to compile if no endian<> specialization is present
76 const char * big_rep
= "\x12\x34\x56\x78\x9A\xBC\xDE\xF0";
77 const char * little_rep
= "\xF0\xDE\xBC\x9A\x78\x56\x34\x12";
79 template <class Endian
>
80 void verify_representation( bool is_big
, int line
)
83 Endian
x ( static_cast<typename
Endian::value_type
>
84 (0x123456789abcdef0LL
+ silence
) ); // will truncate
88 reinterpret_cast<const char*>(big_rep
)+8-sizeof(Endian
),
89 sizeof(Endian
) ) == 0, line
);
91 verify( memcmp( &x
, little_rep
, sizeof(Endian
) ) == 0, line
);
94 template <class Endian
>
95 inline void verify_native_representation( int line
)
97 # ifdef BOOST_BIG_ENDIAN
98 verify_representation
<Endian
>( true, line
);
100 verify_representation
<Endian
>( false, line
);
104 // detect_endianness -----------------------------------------------------//
106 void detect_endianness()
114 View v
= { 0x0102030405060708LL
}; // initialize v.i
116 if ( memcmp( v
.c
, "\10\7\6\5\4\3\2\1", 8) == 0 )
118 cout
<< "This machine is little-endian.\n";
119 # ifdef BOOST_BIG_INTEGER_OPERATORS
120 cout
<< "yet boost/detail/endian.hpp defines BOOST_BIG_INTEGER_OPERATORS.\n"
121 "You must fix boost/detail/endian.hpp for boost/endian.hpp to work correctly.\n"
122 "Please report the fix to the Boost mailing list.\n";
126 else if ( memcmp( v
.c
, "\1\2\3\4\5\6\7\10", 8) == 0 )
128 cout
<< "This machine is big-endian.\n";
129 # ifdef BOOST_LITTLE_INTEGER_OPERATORS
130 cout
<< "yet boost/detail/endian.hpp defines BOOST__LITTLE_INTEGER_OPERATORS.\n"
131 "You must fix boost/detail/endian.hpp for boost/endian.hpp to work correctly.\n"
132 "Please report the fix to the Boost mailing list.\n";
138 cout
<< "This machine is neither strict big-endian nor strict little-endian\n"
139 "You must modify boost/endian.hpp for it to work correctly.\n";
142 cout
<< "That should not matter and is presented for your information only.\n";
143 } // detect_endianness
145 // check_size ------------------------------------------------------------//
149 VERIFY( numeric_limits
<signed char>::digits
== 7 );
150 VERIFY( numeric_limits
<unsigned char>::digits
== 8 );
152 VERIFY_SIZE( sizeof( big8_t
), 1 );
153 VERIFY_SIZE( sizeof( big16_t
), 2 );
154 VERIFY_SIZE( sizeof( big24_t
), 3 );
155 VERIFY_SIZE( sizeof( big32_t
), 4 );
156 VERIFY_SIZE( sizeof( big40_t
), 5 );
157 VERIFY_SIZE( sizeof( big48_t
), 6 );
158 VERIFY_SIZE( sizeof( big56_t
), 7 );
159 VERIFY_SIZE( sizeof( big64_t
), 8 );
161 VERIFY_SIZE( sizeof( ubig8_t
), 1 );
162 VERIFY_SIZE( sizeof( ubig16_t
), 2 );
163 VERIFY_SIZE( sizeof( ubig24_t
), 3 );
164 VERIFY_SIZE( sizeof( ubig32_t
), 4 );
165 VERIFY_SIZE( sizeof( ubig40_t
), 5 );
166 VERIFY_SIZE( sizeof( ubig48_t
), 6 );
167 VERIFY_SIZE( sizeof( ubig56_t
), 7 );
168 VERIFY_SIZE( sizeof( ubig64_t
), 8 );
170 VERIFY_SIZE( sizeof( little8_t
), 1 );
171 VERIFY_SIZE( sizeof( little16_t
), 2 );
172 VERIFY_SIZE( sizeof( little24_t
), 3 );
173 VERIFY_SIZE( sizeof( little32_t
), 4 );
174 VERIFY_SIZE( sizeof( little40_t
), 5 );
175 VERIFY_SIZE( sizeof( little48_t
), 6 );
176 VERIFY_SIZE( sizeof( little56_t
), 7 );
177 VERIFY_SIZE( sizeof( little64_t
), 8 );
179 VERIFY_SIZE( sizeof( ulittle8_t
), 1 );
180 VERIFY_SIZE( sizeof( ulittle16_t
), 2 );
181 VERIFY_SIZE( sizeof( ulittle24_t
), 3 );
182 VERIFY_SIZE( sizeof( ulittle32_t
), 4 );
183 VERIFY_SIZE( sizeof( ulittle40_t
), 5 );
184 VERIFY_SIZE( sizeof( ulittle48_t
), 6 );
185 VERIFY_SIZE( sizeof( ulittle56_t
), 7 );
186 VERIFY_SIZE( sizeof( ulittle64_t
), 8 );
188 VERIFY_SIZE( sizeof( native8_t
), 1 );
189 VERIFY_SIZE( sizeof( native16_t
), 2 );
190 VERIFY_SIZE( sizeof( native24_t
), 3 );
191 VERIFY_SIZE( sizeof( native32_t
), 4 );
192 VERIFY_SIZE( sizeof( native40_t
), 5 );
193 VERIFY_SIZE( sizeof( native48_t
), 6 );
194 VERIFY_SIZE( sizeof( native56_t
), 7 );
195 VERIFY_SIZE( sizeof( native64_t
), 8 );
197 VERIFY_SIZE( sizeof( unative8_t
), 1 );
198 VERIFY_SIZE( sizeof( unative16_t
), 2 );
199 VERIFY_SIZE( sizeof( unative24_t
), 3 );
200 VERIFY_SIZE( sizeof( unative32_t
), 4 );
201 VERIFY_SIZE( sizeof( unative40_t
), 5 );
202 VERIFY_SIZE( sizeof( unative48_t
), 6 );
203 VERIFY_SIZE( sizeof( unative56_t
), 7 );
204 VERIFY_SIZE( sizeof( unative64_t
), 8 );
206 VERIFY_SIZE( sizeof( aligned_big16_t
), 2 );
207 VERIFY_SIZE( sizeof( aligned_big32_t
), 4 );
208 VERIFY_SIZE( sizeof( aligned_big64_t
), 8 );
210 VERIFY_SIZE( sizeof( aligned_ubig16_t
), 2 );
211 VERIFY_SIZE( sizeof( aligned_ubig32_t
), 4 );
212 VERIFY_SIZE( sizeof( aligned_ubig64_t
), 8 );
214 VERIFY_SIZE( sizeof( aligned_little16_t
), 2 );
215 VERIFY_SIZE( sizeof( aligned_little32_t
), 4 );
216 VERIFY_SIZE( sizeof( aligned_little64_t
), 8 );
218 VERIFY_SIZE( sizeof( aligned_ulittle16_t
), 2 );
219 VERIFY_SIZE( sizeof( aligned_ulittle32_t
), 4 );
220 VERIFY_SIZE( sizeof( aligned_ulittle64_t
), 8 );
223 // check_alignment -------------------------------------------------------//
225 void check_alignment()
227 // structs with offsets % 2 == 1 for type of size > 1 to ensure no alignment
228 // bytes added for any size > 1
275 struct ulittle_struct
305 struct unative_struct
320 int saved_err_count
= err_count
;
322 VERIFY_SIZE( sizeof(big_struct
), 39 );
323 VERIFY_SIZE( sizeof(ubig_struct
), 39 );
324 VERIFY_SIZE( sizeof(little_struct
), 39 );
325 VERIFY_SIZE( sizeof(ulittle_struct
), 39 );
326 VERIFY_SIZE( sizeof(native_struct
), 39 );
327 VERIFY_SIZE( sizeof(unative_struct
), 39 );
329 if ( saved_err_count
== err_count
)
332 "Size and alignment for structures of endian types are as expected.\n";
336 // check_representation_and_range_and_ops --------------------------------//
338 void check_representation_and_range_and_ops()
341 VERIFY_BIG_REPRESENTATION( big8_t
);
342 VERIFY_VALUE_AND_OPS( big8_t
, int_least8_t, 0x7f );
343 VERIFY_VALUE_AND_OPS( big8_t
, int_least8_t, -0x80 );
345 VERIFY_BIG_REPRESENTATION( big16_t
);
346 VERIFY_VALUE_AND_OPS( big16_t
, int_least16_t, 0x7fff );
347 VERIFY_VALUE_AND_OPS( big16_t
, int_least16_t, -0x8000 );
349 VERIFY_BIG_REPRESENTATION( big24_t
);
350 VERIFY_VALUE_AND_OPS( big24_t
, int_least32_t, 0x7fffff );
351 VERIFY_VALUE_AND_OPS( big24_t
, int_least32_t, -0x800000 );
353 VERIFY_BIG_REPRESENTATION( big32_t
);
354 VERIFY_VALUE_AND_OPS( big32_t
, int_least32_t, 0x7fffffff );
355 VERIFY_VALUE_AND_OPS( big32_t
, int_least32_t, -0x7fffffff-1 );
357 VERIFY_BIG_REPRESENTATION( big40_t
);
358 VERIFY_VALUE_AND_OPS( big40_t
, int_least64_t, 0x7fffffffffLL
);
359 VERIFY_VALUE_AND_OPS( big40_t
, int_least64_t, -0x8000000000LL
);
361 VERIFY_BIG_REPRESENTATION( big48_t
);
362 VERIFY_VALUE_AND_OPS( big48_t
, int_least64_t, 0x7fffffffffffLL
);
363 VERIFY_VALUE_AND_OPS( big48_t
, int_least64_t, -0x800000000000LL
);
365 VERIFY_BIG_REPRESENTATION( big56_t
);
366 VERIFY_VALUE_AND_OPS( big56_t
, int_least64_t, 0x7fffffffffffffLL
);
367 VERIFY_VALUE_AND_OPS( big56_t
, int_least64_t, -0x80000000000000LL
);
369 VERIFY_BIG_REPRESENTATION( big64_t
);
370 VERIFY_VALUE_AND_OPS( big64_t
, int_least64_t, 0x7fffffffffffffffLL
);
371 VERIFY_VALUE_AND_OPS( big64_t
, int_least64_t, -0x7fffffffffffffffLL
-1 );
373 VERIFY_BIG_REPRESENTATION( ubig8_t
);
374 VERIFY_VALUE_AND_OPS( ubig8_t
, uint_least8_t, 0xff );
376 VERIFY_BIG_REPRESENTATION( ubig16_t
);
377 VERIFY_VALUE_AND_OPS( ubig16_t
, uint_least16_t, 0xffff );
379 VERIFY_BIG_REPRESENTATION( ubig24_t
);
380 VERIFY_VALUE_AND_OPS( ubig24_t
, uint_least32_t, 0xffffff );
382 VERIFY_BIG_REPRESENTATION( ubig32_t
);
383 VERIFY_VALUE_AND_OPS( ubig32_t
, uint_least32_t, 0xffffffff );
385 VERIFY_BIG_REPRESENTATION( ubig40_t
);
386 VERIFY_VALUE_AND_OPS( ubig40_t
, uint_least64_t, 0xffffffffffLL
);
388 VERIFY_BIG_REPRESENTATION( ubig48_t
);
389 VERIFY_VALUE_AND_OPS( ubig48_t
, uint_least64_t, 0xffffffffffffLL
);
391 VERIFY_BIG_REPRESENTATION( ubig56_t
);
392 VERIFY_VALUE_AND_OPS( ubig56_t
, uint_least64_t, 0xffffffffffffffLL
);
394 VERIFY_BIG_REPRESENTATION( ubig64_t
);
395 VERIFY_VALUE_AND_OPS( ubig64_t
, uint_least64_t, 0xffffffffffffffffLL
);
397 VERIFY_LITTLE_REPRESENTATION( little8_t
);
398 VERIFY_VALUE_AND_OPS( little8_t
, int_least8_t, 0x7f );
399 VERIFY_VALUE_AND_OPS( little8_t
, int_least8_t, -0x80 );
401 VERIFY_LITTLE_REPRESENTATION( little16_t
);
402 VERIFY_VALUE_AND_OPS( little16_t
, int_least16_t, 0x7fff );
403 VERIFY_VALUE_AND_OPS( little16_t
, int_least16_t, -0x8000 );
405 VERIFY_LITTLE_REPRESENTATION( little24_t
);
406 VERIFY_VALUE_AND_OPS( little24_t
, int_least32_t, 0x7fffff );
407 VERIFY_VALUE_AND_OPS( little24_t
, int_least32_t, -0x800000 );
409 VERIFY_LITTLE_REPRESENTATION( little32_t
);
410 VERIFY_VALUE_AND_OPS( little32_t
, int_least32_t, 0x7fffffff );
411 VERIFY_VALUE_AND_OPS( little32_t
, int_least32_t, -0x7fffffff-1 );
413 VERIFY_LITTLE_REPRESENTATION( little40_t
);
414 VERIFY_VALUE_AND_OPS( little40_t
, int_least64_t, 0x7fffffffffLL
);
415 VERIFY_VALUE_AND_OPS( little40_t
, int_least64_t, -0x8000000000LL
);
417 VERIFY_LITTLE_REPRESENTATION( little48_t
);
418 VERIFY_VALUE_AND_OPS( little48_t
, int_least64_t, 0x7fffffffffffLL
);
419 VERIFY_VALUE_AND_OPS( little48_t
, int_least64_t, -0x800000000000LL
);
421 VERIFY_LITTLE_REPRESENTATION( little56_t
);
422 VERIFY_VALUE_AND_OPS( little56_t
, int_least64_t, 0x7fffffffffffffLL
);
423 VERIFY_VALUE_AND_OPS( little56_t
, int_least64_t, -0x80000000000000LL
);
425 VERIFY_LITTLE_REPRESENTATION( little64_t
);
426 VERIFY_VALUE_AND_OPS( little64_t
, int_least64_t, 0x7fffffffffffffffLL
);
427 VERIFY_VALUE_AND_OPS( little64_t
, int_least64_t, -0x7fffffffffffffffLL
-1 );
429 VERIFY_LITTLE_REPRESENTATION( ulittle8_t
);
430 VERIFY_VALUE_AND_OPS( ulittle8_t
, uint_least8_t, 0xff );
432 VERIFY_LITTLE_REPRESENTATION( ulittle16_t
);
433 VERIFY_VALUE_AND_OPS( ulittle16_t
, uint_least16_t, 0xffff );
435 VERIFY_LITTLE_REPRESENTATION( ulittle24_t
);
436 VERIFY_VALUE_AND_OPS( ulittle24_t
, uint_least32_t, 0xffffff );
438 VERIFY_LITTLE_REPRESENTATION( ulittle32_t
);
439 VERIFY_VALUE_AND_OPS( ulittle32_t
, uint_least32_t, 0xffffffff );
441 VERIFY_LITTLE_REPRESENTATION( ulittle40_t
);
442 VERIFY_VALUE_AND_OPS( ulittle40_t
, uint_least64_t, 0xffffffffffLL
);
444 VERIFY_LITTLE_REPRESENTATION( ulittle48_t
);
445 VERIFY_VALUE_AND_OPS( ulittle48_t
, uint_least64_t, 0xffffffffffffLL
);
447 VERIFY_LITTLE_REPRESENTATION( ulittle56_t
);
448 VERIFY_VALUE_AND_OPS( ulittle56_t
, uint_least64_t, 0xffffffffffffffLL
);
450 VERIFY_LITTLE_REPRESENTATION( ulittle64_t
);
451 VERIFY_VALUE_AND_OPS( ulittle64_t
, uint_least64_t, 0xffffffffffffffffLL
);
453 VERIFY_NATIVE_REPRESENTATION( native8_t
);
454 VERIFY_VALUE_AND_OPS( native8_t
, int_least8_t, 0x7f );
455 VERIFY_VALUE_AND_OPS( native8_t
, int_least8_t, -0x80 );
457 VERIFY_NATIVE_REPRESENTATION( native16_t
);
458 VERIFY_VALUE_AND_OPS( native16_t
, int_least16_t, 0x7fff );
459 VERIFY_VALUE_AND_OPS( native16_t
, int_least16_t, -0x8000 );
461 VERIFY_NATIVE_REPRESENTATION( native24_t
);
462 VERIFY_VALUE_AND_OPS( native24_t
, int_least32_t, 0x7fffff );
463 VERIFY_VALUE_AND_OPS( native24_t
, int_least32_t, -0x800000 );
465 VERIFY_NATIVE_REPRESENTATION( native32_t
);
466 VERIFY_VALUE_AND_OPS( native32_t
, int_least32_t, 0x7fffffff );
467 VERIFY_VALUE_AND_OPS( native32_t
, int_least32_t, -0x7fffffff-1 );
469 VERIFY_NATIVE_REPRESENTATION( native40_t
);
470 VERIFY_VALUE_AND_OPS( native40_t
, int_least64_t, 0x7fffffffffLL
);
471 VERIFY_VALUE_AND_OPS( native40_t
, int_least64_t, -0x8000000000LL
);
473 VERIFY_NATIVE_REPRESENTATION( native48_t
);
474 VERIFY_VALUE_AND_OPS( native48_t
, int_least64_t, 0x7fffffffffffLL
);
475 VERIFY_VALUE_AND_OPS( native48_t
, int_least64_t, -0x800000000000LL
);
477 VERIFY_NATIVE_REPRESENTATION( native56_t
);
478 VERIFY_VALUE_AND_OPS( native56_t
, int_least64_t, 0x7fffffffffffffLL
);
479 VERIFY_VALUE_AND_OPS( native56_t
, int_least64_t, -0x80000000000000LL
);
481 VERIFY_NATIVE_REPRESENTATION( native64_t
);
482 VERIFY_VALUE_AND_OPS( native64_t
, int_least64_t, 0x7fffffffffffffffLL
);
483 VERIFY_VALUE_AND_OPS( native64_t
, int_least64_t, -0x7fffffffffffffffLL
-1 );
485 VERIFY_NATIVE_REPRESENTATION( unative8_t
);
486 VERIFY_VALUE_AND_OPS( unative8_t
, uint_least8_t, 0xff );
488 VERIFY_NATIVE_REPRESENTATION( unative16_t
);
489 VERIFY_VALUE_AND_OPS( unative16_t
, uint_least16_t, 0xffff );
491 VERIFY_NATIVE_REPRESENTATION( unative24_t
);
492 VERIFY_VALUE_AND_OPS( unative24_t
, uint_least32_t, 0xffffff );
494 VERIFY_NATIVE_REPRESENTATION( unative32_t
);
495 VERIFY_VALUE_AND_OPS( unative32_t
, uint_least32_t, 0xffffffff );
497 VERIFY_NATIVE_REPRESENTATION( unative40_t
);
498 VERIFY_VALUE_AND_OPS( unative40_t
, uint_least64_t, 0xffffffffffLL
);
500 VERIFY_NATIVE_REPRESENTATION( unative48_t
);
501 VERIFY_VALUE_AND_OPS( unative48_t
, uint_least64_t, 0xffffffffffffLL
);
503 VERIFY_NATIVE_REPRESENTATION( unative56_t
);
504 VERIFY_VALUE_AND_OPS( unative56_t
, uint_least64_t, 0xffffffffffffffLL
);
506 VERIFY_NATIVE_REPRESENTATION( unative64_t
);
507 VERIFY_VALUE_AND_OPS( unative64_t
, uint_least64_t, 0xffffffffffffffffLL
);
509 VERIFY_BIG_REPRESENTATION( aligned_big16_t
);
510 VERIFY_VALUE_AND_OPS( aligned_big16_t
, int_least16_t, 0x7fff );
511 VERIFY_VALUE_AND_OPS( aligned_big16_t
, int_least16_t, -0x8000 );
513 VERIFY_BIG_REPRESENTATION( aligned_big32_t
);
514 VERIFY_VALUE_AND_OPS( aligned_big32_t
, int_least32_t, 0x7fffffff );
515 VERIFY_VALUE_AND_OPS( aligned_big32_t
, int_least32_t, -0x7fffffff-1 );
517 VERIFY_BIG_REPRESENTATION( aligned_big64_t
);
518 VERIFY_VALUE_AND_OPS( aligned_big64_t
, int_least64_t, 0x7fffffffffffffffLL
);
519 VERIFY_VALUE_AND_OPS( aligned_big64_t
, int_least64_t, -0x7fffffffffffffffLL
-1 );
521 VERIFY_BIG_REPRESENTATION( aligned_ubig16_t
);
522 VERIFY_VALUE_AND_OPS( aligned_ubig16_t
, uint_least16_t, 0xffff );
524 VERIFY_BIG_REPRESENTATION( aligned_ubig32_t
);
525 VERIFY_VALUE_AND_OPS( aligned_ubig32_t
, uint_least32_t, 0xffffffff );
527 VERIFY_BIG_REPRESENTATION( aligned_ubig64_t
);
528 VERIFY_VALUE_AND_OPS( aligned_ubig64_t
, uint_least64_t, 0xffffffffffffffffLL
);
530 VERIFY_LITTLE_REPRESENTATION( aligned_little16_t
);
531 VERIFY_VALUE_AND_OPS( aligned_little16_t
, int_least16_t, 0x7fff );
532 VERIFY_VALUE_AND_OPS( aligned_little16_t
, int_least16_t, -0x8000 );
534 VERIFY_LITTLE_REPRESENTATION( aligned_little32_t
);
535 VERIFY_VALUE_AND_OPS( aligned_little32_t
, int_least32_t, 0x7fffffff );
536 VERIFY_VALUE_AND_OPS( aligned_little32_t
, int_least32_t, -0x7fffffff-1 );
538 VERIFY_LITTLE_REPRESENTATION( aligned_little64_t
);
539 VERIFY_VALUE_AND_OPS( aligned_little64_t
, int_least64_t, 0x7fffffffffffffffLL
);
540 VERIFY_VALUE_AND_OPS( aligned_little64_t
, int_least64_t, -0x7fffffffffffffffLL
-1 );
542 VERIFY_LITTLE_REPRESENTATION( aligned_ulittle16_t
);
543 VERIFY_VALUE_AND_OPS( aligned_ulittle16_t
, uint_least16_t, 0xffff );
545 VERIFY_LITTLE_REPRESENTATION( aligned_ulittle32_t
);
546 VERIFY_VALUE_AND_OPS( aligned_ulittle32_t
, uint_least32_t, 0xffffffff );
548 VERIFY_LITTLE_REPRESENTATION( aligned_ulittle64_t
);
549 VERIFY_VALUE_AND_OPS( aligned_ulittle64_t
, uint_least64_t, 0xffffffffffffffffLL
);
551 } // check_representation_and_range
553 long iterations
= 10000000;
555 template< class Endian
>
556 Endian
timing_test( const char * s
)
558 cout
<< s
<< " timing test, " << iterations
<< " iterations: ";
562 for ( long i
= 0; i
< iterations
; ++i
)
568 if ( i
== 0 ) VERIFY_VALUE_AND_OPS( Endian
, typename
Endian::value_type
, 21 );
573 } // unnamed namespace
575 int main( int argc
, char * argv
[] )
578 << argv
[0] << " [#],\n where # specifies iteration count\n"
579 " default iteration count is 1000000" << endl
;
582 iterations
= atol( argv
[1] );
583 if ( iterations
< 1 ) iterations
= 1;
588 check_representation_and_range_and_ops();
590 //timing_test<big32_t> ( "big32_t" );
591 //timing_test<aligned_big32_t>( "aligned_big32_t" );
592 //timing_test<little32_t> ( "little32_t" );
593 //timing_test<aligned_little32_t>( "aligned_little32_t" );
595 cout
<< "\n" << err_count
<< " errors detected\nTest "
596 << (err_count
==0 ? "passed\n\n" : "failed\n\n");
598 return err_count
? 1 : 0;