I'm going through the code of Unix version 6 with the Lion's book. One of the header files (param.h, can be accessed here) defines the following structs:
/*struct to access integers*/
/*single integer */
struct { int integ; };
/*in bytes*/
struct { char lobyte; char hibyte; };
These structures don't seem to define any instance, nor are they named so they can be used later. Does anybody know what is their use?
Thanks
If someone included the whole file in a union declaration, it would allow them to access the different parts.
It would be something like:
union{
#include <param.h>
} myparam;
myparam.integ = 0xDEAD;
assert(myparam.lobyte == 0xAD)
assert(myparam.hibyte == 0xDE)
(Depends on endianness of architecture...)
So having looked around a bit, it seems that in old versions of C, you wouldn't have needed to declare the union ; there was only one namespace for all struct/union members that just translated into a byte offset that you could use on any variable. The best mention of this I could find is here : http://docs.sun.com/source/806-3567/compat.html Describing pre-ISO Sun C:
Allows struct, union, and arithmetic types using member selection operators ('.', '->') to work on members of other struct(s) or unions.
Back in those days, the members of structures all shared the same namespace, not one namespace per structure. Consequently, each element of a structure had to have a unique name across all structures, or the same element had to appear with the same type at the same offset in every structure in which it appeared. Quite how that was used with these, I'm not sure, but I suspect you could do:
int x;
x.lobyte = 1;
x.hibyte = 2;
Or something analogous to that.
See also:
(Neither of those seems to answer this question, though.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With