Fix boo boos detected by inspect program.

This commit is contained in:
Beman
2013-05-29 09:40:35 -04:00
parent 457ed73778
commit db3864b3d4
5 changed files with 49 additions and 51 deletions

View File

@@ -174,7 +174,7 @@ type (possibly <code>const</code>) <code>ReversibleValue</code>.</p>
<td valign="top"> <td valign="top">
<p><code>reverse_value(x)</code></td> <p><code>reverse_value(x)</code></td>
<td valign="top"> <td valign="top">
<p><a name="ReversibleValue"><code>ReversibleValue</code></a></td> <p><code>ReversibleValue</code></td>
<td> <td>
<p>The returned value is the value of <code>x</code> with the <p>The returned value is the value of <code>x</code> with the
order of its constituent bytes reversed.</td> order of its constituent bytes reversed.</td>

View File

@@ -50,8 +50,7 @@
<a href="#Example">Example</a><br> <a href="#Example">Example</a><br>
<a href="#Limitations">Limitations</a><br> <a href="#Limitations">Limitations</a><br>
<a href="#Feature-set">Feature set</a><br> <a href="#Feature-set">Feature set</a><br>
<a href="#Types">Typedefs</a><br> <a href="#Types">Enums and typedefs</a><br>
&nbsp;&nbsp;&nbsp; <a href="#Comment-on-naming">Comment on naming</a><br>
<a href="#Class_template_endian">Class template <code>endian</code></a><br> <a href="#Class_template_endian">Class template <code>endian</code></a><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<a href="#Synopsis">Synopsis</a><br> <a href="#Synopsis">Synopsis</a><br>
@@ -172,7 +171,7 @@ int main(int, char* [])
} }
</pre> </pre>
</blockquote> </blockquote>
<p>After compiling and executing <a href="endian_example.cpp">endian_example.cpp</a>, <p>After compiling and executing <a href="../example/endian_example.cpp">endian_example.cpp</a>,
a hex dump of <code>test.dat</code> shows:</p> a hex dump of <code>test.dat</code> shows:</p>
<blockquote> <blockquote>
<pre>01020304 00000010 01000000 04030201</pre> <pre>01020304 00000010 01000000 04030201</pre>
@@ -617,7 +616,7 @@ differs from endian representation size. Vicente Botet and other reviewers
suggested supporting floating point types.</p> suggested supporting floating point types.</p>
<hr> <hr>
<p>Last revised: <p>Last revised:
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->28 May, 2013<!--webbot bot="Timestamp" endspan i-checksum="13992" --></p> <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->29 May, 2013<!--webbot bot="Timestamp" endspan i-checksum="13994" --></p>
<p>© Copyright Beman Dawes, 2006-2009, 2013</p> <p>© Copyright Beman Dawes, 2006-2009, 2013</p>
<p>Distributed under the Boost Software License, Version 1.0. See <p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/ LICENSE_1_0.txt</a></p> <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/ LICENSE_1_0.txt</a></p>

View File

@@ -319,7 +319,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT { return m_value; } const char* data() const BOOST_NOEXCEPT { return m_value; }
private: private:
char m_value[n_bits/8]; char m_value[n_bits/8];
}; };
// unaligned float big endian specialization // unaligned float big endian specialization
@@ -344,7 +344,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT { return m_value; } const char* data() const BOOST_NOEXCEPT { return m_value; }
private: private:
char m_value[sizeof(value_type)]; char m_value[sizeof(value_type)];
}; };
// unaligned double big endian specialization // unaligned double big endian specialization
@@ -369,7 +369,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT { return m_value; } const char* data() const BOOST_NOEXCEPT { return m_value; }
private: private:
char m_value[sizeof(value_type)]; char m_value[sizeof(value_type)];
}; };
// unaligned float little endian specialization // unaligned float little endian specialization
@@ -394,7 +394,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT { return m_value; } const char* data() const BOOST_NOEXCEPT { return m_value; }
private: private:
char m_value[sizeof(value_type)]; char m_value[sizeof(value_type)];
}; };
// unaligned double little endian specialization // unaligned double little endian specialization
@@ -419,7 +419,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT { return m_value; } const char* data() const BOOST_NOEXCEPT { return m_value; }
private: private:
char m_value[sizeof(value_type)]; char m_value[sizeof(value_type)];
}; };
// unaligned little endian specialization // unaligned little endian specialization
@@ -453,7 +453,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT { return m_value; } const char* data() const BOOST_NOEXCEPT { return m_value; }
private: private:
char m_value[n_bits/8]; char m_value[n_bits/8];
}; };
// unaligned native endian specialization // unaligned native endian specialization
@@ -485,7 +485,7 @@ namespace endian
# endif # endif
const char* data() const BOOST_NOEXCEPT { return m_value; } const char* data() const BOOST_NOEXCEPT { return m_value; }
private: private:
char m_value[n_bits/8]; char m_value[n_bits/8];
}; };
// align::yes specializations; only n_bits == 16/32/64 supported // align::yes specializations; only n_bits == 16/32/64 supported
@@ -526,7 +526,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT {return reinterpret_cast<const char*>(&m_value);} const char* data() const BOOST_NOEXCEPT {return reinterpret_cast<const char*>(&m_value);}
private: private:
T m_value; T m_value;
}; };
// aligned little endian specialization // aligned little endian specialization
@@ -565,7 +565,7 @@ namespace endian
} }
const char* data() const BOOST_NOEXCEPT {return reinterpret_cast<const char*>(&m_value);} const char* data() const BOOST_NOEXCEPT {return reinterpret_cast<const char*>(&m_value);}
private: private:
T m_value; T m_value;
}; };
} // namespace endian } // namespace endian

View File

@@ -559,74 +559,74 @@ namespace
void check_representation_and_range_and_ops() void check_representation_and_range_and_ops()
{ {
// aligned floating point types // aligned floating point types
float big_float32_expected = std::numeric_limits<float>::max(); float big_float32_expected = (std::numeric_limits<float>::max) ();
boost::endian::big_endian(big_float32_expected); boost::endian::big_endian(big_float32_expected);
big_float32_t big_float32(std::numeric_limits<float>::max()); big_float32_t big_float32((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(big_float32.data(), VERIFY(std::memcmp(big_float32.data(),
reinterpret_cast<const char*>(&big_float32_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&big_float32_expected), sizeof(float)) == 0);
float little_float32_expected = std::numeric_limits<float>::max(); float little_float32_expected = (std::numeric_limits<float>::max) ();
boost::endian::little_endian(little_float32_expected); boost::endian::little_endian(little_float32_expected);
little_float32_t little_float32(std::numeric_limits<float>::max()); little_float32_t little_float32((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(little_float32.data(), VERIFY(std::memcmp(little_float32.data(),
reinterpret_cast<const char*>(&little_float32_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&little_float32_expected), sizeof(float)) == 0);
double big_float64_expected = std::numeric_limits<double>::max(); double big_float64_expected = (std::numeric_limits<double>::max) ();
boost::endian::big_endian(big_float64_expected); boost::endian::big_endian(big_float64_expected);
big_float64_t big_float64(std::numeric_limits<double>::max()); big_float64_t big_float64((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(big_float64.data(), VERIFY(std::memcmp(big_float64.data(),
reinterpret_cast<const char*>(&big_float64_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&big_float64_expected), sizeof(double)) == 0);
double little_float64_expected = std::numeric_limits<double>::max(); double little_float64_expected = (std::numeric_limits<double>::max) ();
boost::endian::little_endian(little_float64_expected); boost::endian::little_endian(little_float64_expected);
little_float64_t little_float64(std::numeric_limits<double>::max()); little_float64_t little_float64((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(little_float64.data(), VERIFY(std::memcmp(little_float64.data(),
reinterpret_cast<const char*>(&little_float64_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&little_float64_expected), sizeof(double)) == 0);
VERIFY_VALUE_AND_OPS( big_float32_t, float, std::numeric_limits<float>::max() ); VERIFY_VALUE_AND_OPS( big_float32_t, float, (std::numeric_limits<float>::max) () );
VERIFY_VALUE_AND_OPS( big_float32_t, float, std::numeric_limits<float>::min() ); VERIFY_VALUE_AND_OPS( big_float32_t, float, (std::numeric_limits<float>::min) () );
VERIFY_VALUE_AND_OPS( big_float64_t, double, std::numeric_limits<double>::max() ); VERIFY_VALUE_AND_OPS( big_float64_t, double, (std::numeric_limits<double>::max) () );
VERIFY_VALUE_AND_OPS( big_float64_t, double, std::numeric_limits<double>::min() ); VERIFY_VALUE_AND_OPS( big_float64_t, double, (std::numeric_limits<double>::min) () );
VERIFY_VALUE_AND_OPS( little_float32_t, float, std::numeric_limits<float>::max() ); VERIFY_VALUE_AND_OPS( little_float32_t, float, (std::numeric_limits<float>::max) () );
VERIFY_VALUE_AND_OPS( little_float32_t, float, std::numeric_limits<float>::min() ); VERIFY_VALUE_AND_OPS( little_float32_t, float, (std::numeric_limits<float>::min) () );
VERIFY_VALUE_AND_OPS( little_float64_t, double, std::numeric_limits<double>::max() ); VERIFY_VALUE_AND_OPS( little_float64_t, double, (std::numeric_limits<double>::max) () );
VERIFY_VALUE_AND_OPS( little_float64_t, double, std::numeric_limits<double>::min() ); VERIFY_VALUE_AND_OPS( little_float64_t, double, (std::numeric_limits<double>::min) () );
// unaligned floating point types // unaligned floating point types
float big_float32un_expected = std::numeric_limits<float>::max(); float big_float32un_expected = (std::numeric_limits<float>::max) ();
boost::endian::big_endian(big_float32un_expected); boost::endian::big_endian(big_float32un_expected);
big_float32un_t big_float32un(std::numeric_limits<float>::max()); big_float32un_t big_float32un((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(big_float32un.data(), VERIFY(std::memcmp(big_float32un.data(),
reinterpret_cast<const char*>(&big_float32un_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&big_float32un_expected), sizeof(float)) == 0);
float little_float32un_expected = std::numeric_limits<float>::max(); float little_float32un_expected = (std::numeric_limits<float>::max) ();
boost::endian::little_endian(little_float32un_expected); boost::endian::little_endian(little_float32un_expected);
little_float32un_t little_float32un(std::numeric_limits<float>::max()); little_float32un_t little_float32un((std::numeric_limits<float>::max) ());
VERIFY(std::memcmp(little_float32un.data(), VERIFY(std::memcmp(little_float32un.data(),
reinterpret_cast<const char*>(&little_float32un_expected), sizeof(float)) == 0); reinterpret_cast<const char*>(&little_float32un_expected), sizeof(float)) == 0);
double big_float64un_expected = std::numeric_limits<double>::max(); double big_float64un_expected = (std::numeric_limits<double>::max) ();
boost::endian::big_endian(big_float64un_expected); boost::endian::big_endian(big_float64un_expected);
big_float64un_t big_float64un(std::numeric_limits<double>::max()); big_float64un_t big_float64un((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(big_float64un.data(), VERIFY(std::memcmp(big_float64un.data(),
reinterpret_cast<const char*>(&big_float64un_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&big_float64un_expected), sizeof(double)) == 0);
double little_float64un_expected = std::numeric_limits<double>::max(); double little_float64un_expected = (std::numeric_limits<double>::max) ();
boost::endian::little_endian(little_float64un_expected); boost::endian::little_endian(little_float64un_expected);
little_float64un_t little_float64un(std::numeric_limits<double>::max()); little_float64un_t little_float64un((std::numeric_limits<double>::max) ());
VERIFY(std::memcmp(little_float64un.data(), VERIFY(std::memcmp(little_float64un.data(),
reinterpret_cast<const char*>(&little_float64un_expected), sizeof(double)) == 0); reinterpret_cast<const char*>(&little_float64un_expected), sizeof(double)) == 0);
VERIFY_VALUE_AND_OPS( big_float32un_t, float, std::numeric_limits<float>::max() ); VERIFY_VALUE_AND_OPS( big_float32un_t, float, (std::numeric_limits<float>::max) () );
VERIFY_VALUE_AND_OPS( big_float32un_t, float, std::numeric_limits<float>::min() ); VERIFY_VALUE_AND_OPS( big_float32un_t, float, (std::numeric_limits<float>::min) () );
VERIFY_VALUE_AND_OPS( big_float64un_t, double, std::numeric_limits<double>::max() ); VERIFY_VALUE_AND_OPS( big_float64un_t, double, (std::numeric_limits<double>::max) () );
VERIFY_VALUE_AND_OPS( big_float64un_t, double, std::numeric_limits<double>::min() ); VERIFY_VALUE_AND_OPS( big_float64un_t, double, (std::numeric_limits<double>::min) () );
VERIFY_VALUE_AND_OPS( little_float32un_t, float, std::numeric_limits<float>::max() ); VERIFY_VALUE_AND_OPS( little_float32un_t, float, (std::numeric_limits<float>::max) () );
VERIFY_VALUE_AND_OPS( little_float32un_t, float, std::numeric_limits<float>::min() ); VERIFY_VALUE_AND_OPS( little_float32un_t, float, (std::numeric_limits<float>::min) () );
VERIFY_VALUE_AND_OPS( little_float64un_t, double, std::numeric_limits<double>::max() ); VERIFY_VALUE_AND_OPS( little_float64un_t, double, (std::numeric_limits<double>::max) () );
VERIFY_VALUE_AND_OPS( little_float64un_t, double, std::numeric_limits<double>::min() ); VERIFY_VALUE_AND_OPS( little_float64un_t, double, (std::numeric_limits<double>::min) () );
float a = 1.0F; float a = 1.0F;
big_float32_t b(1.0F); big_float32_t b(1.0F);

View File

@@ -5,8 +5,7 @@
#include "test.hpp" #include "test.hpp"
#include <iostream> #include <iostream>
#include <cassert> #include <boost/assert.hpp>
//#include <cstdint>
typedef unsigned short uint16_t; typedef unsigned short uint16_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
@@ -18,11 +17,11 @@ int main()
#ifndef BOOST_ENDIAN_NO_INTRINSICS #ifndef BOOST_ENDIAN_NO_INTRINSICS
uint16_t x2 = 0x1122U; uint16_t x2 = 0x1122U;
assert(BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x2) == 0x2211U); BOOST_ASSERT(BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x2) == 0x2211U);
uint32_t x4 = 0x11223344UL; uint32_t x4 = 0x11223344UL;
assert(BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x4) == 0x44332211UL); BOOST_ASSERT(BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x4) == 0x44332211UL);
uint64_t x8 = 0x1122334455667788U; uint64_t x8 = 0x1122334455667788U;
assert(BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x8) == 0x8877665544332211ULL); BOOST_ASSERT(BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x8) == 0x8877665544332211ULL);
#endif #endif
return 0; return 0;
} }