All of the preceding discussions pertain to file processing with complex data types related to structs. There are a few points about unions that you should be aware of. The first point to note is that a union is a single piece of data as large as its largest data member. It has to be, in order to store a value that fits into that data member.
So a union with a long and an integer data member will be the size of the long integer. When you write the union out to file, you can either:
Write the union directly, as an object.
Write the required union member, individually.
The UnionTest.c program on the companion Web site (go to www.courseptr.com and click on the Downloads button) illustrates the following discussion of these ...