[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppUnion
Avoid union.
This can come in handy, for converting doubles to bits:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppUnion
(C++) union
Keyword enabling you to create a union. A union is a bit like a struct, except that its variables are not seperated in memory.Avoid union.
union MyUnion { unsigned int myUnsignedInt; int myInt; }; int main() { MyUnion myUnion; myUnion.myUnsignedInt = 3000000000; //Higher then the range of an int std::cout << myUnion.myUnsignedInt << std::endl; std::cout << myUnion.myInt << std::endl; myUnion.myInt = -69; //Below the range of en unsigned int std::cout << myUnion.myUnsignedInt << std::endl; std::cout << myUnion.myInt << std::endl; }
- include <iostream>
This can come in handy, for converting doubles to bits:
- STL example: Converting a double to a std::string of bits
- C++ Builder example: Converting a double to a String of bits
Reference
- 1) Bjarne Stroustrup. The C++ Programming Language (3rd edition).ISBN: 0-201-88954-4 Chapter C.14.12 'Avoid union'.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
