previous | start

Simplication of Struct/Union Access with #define

It becomes very tedious to have to mention the union member name as well as the particular struct member of the union and finally the member of that struct.

Minix code uses preprocessor definitions to give names to a dotted expression:

Instead of

  msg.m_u.m_m1.m1i1 = 5;
  msg.m_u.m_m1.m1i2 = 10;

Minix would use this approach

#define m1_i1 m_u.m_m1.m1i1
#define m1_i2 m_u.m_m1.m1i2
  

Then the union member name, m_u doesn't need to be used at all:

  msg.m1_i1 = 5;
  msg.m1_i2 = 10;

Here is a more complete example using appropriate #defines.

Message structures are defined in the header file /usr/src/include/minix/ipc.h, which also contains the #define's to shorten the names for accessing the members of the different structs in the message union.



previous | start