It took me some long time to comprehend the issues involved in using unions, structs, and bit fields in C and C++.
First, for the definition of unions and structs, take a look at this link:
http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/strct.htm
Unions could be used together with structs to reinterpret the same location in memory with different interpretations (similar in spirit to the C++ reinterpret_cast). For examples on this see:
http://www.anyexample.com/programming/cplusplus/example_of_using_union_in_cplusplus.xml
C++ extends the unions and structs, for example see:
http://www.yolinux.com/TUTORIALS/LinuxTutorialC++Structures.html
Bit fields are used to define special-sized integers. This is useful for packing data (e.g. flags) together into one memory location. This, however, is a bad habit and should be avoided as the compiler-generated code to access bit fields is usually inefficient! For more examples on this, see:
http://en.wikipedia.org/wiki/Bit_field
http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/language/ref/clrc03defbitf.htm
http://www.cs.cf.ac.uk/Dave/C/node13.html
http://www.daniweb.com/forums/thread55765.html
http://blogs.msdn.com/oldnewthing/archive/2008/11/26/9143050.aspx
http://osr507doc.sco.com/en/tools/ANSI_F.3.9_Structs.unions.html
Finally, unions and structs could be anonymous! You do not have to give a name to a union. In this case its members become directly accessible within the same scope. Wikipedia calls this "untagged union". For an example see:
http://www.velocityreviews.com/forums/t286529-union-with-anonymous-struct.html
Popular Posts
-
Today I had the opportunity to attend a session given by Dr. Moustafa Youssef on his research. The key point in his talk was about detectin...
-
I spent a scary night yesterday trying to fix my Ubuntu installation. I was a victim for the bug related to libc6. The problem is that afte...
-
In 1975 Widrow et. al. introduced a scientific paper about Adaptive Noise Cancellers (ANCs). Since then, ANCs have been used extensively in...
-
From the gcc man page: -dCHARS CHARS is a sequence of one or more of the following characters, and must not be preceded by a spac...
-
Many times you need to call a function/method that does some really heavy work. However, you don't want this function call to block your...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment