I am reviewing a C program that was written in the early 90's. The program contains a usage of the STRUCT function that I have not seen before, however C is not my strong point.
The program reads a binary data file and displays the contents on the screen. The file contains two slightly different structures, the second structure contains two additional fields.
Code:
struct A_1 {
char a
char b
long c
int d
char e
long v1
long v2
long v3
long v4
long v5
long v6
};
struct B_1 {
char a
char b
long c
int d
char e[6]
char f
char g
long v1
long v2
long v3
long v4
long v5
long v6
};
The first five fields are the same, the difference is the addition of two char fields in the second structure. The structures are defined in A.H.
In the program A.C, amongst all the other code are the lines:
Code:
#include "a.h"
char buffer[40];
struct A_1 *a_1;
struct B_1 *b_1;
Then in main there are these two lines which I don't quite understand. I think they are doing some kind of union function??
Code:
a_1 = (struct A_1 *) buffer;
b_1 = (struct B_1 *) buffer;
Later in the code, it refers to fields in either a_1 or b_1 depending on the value of the first field (a) in the structures. So, it looks like some kind of union, but I'm not seeing it.
Any explanations on how this works would be much appreciated.