O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

File Processing with unions

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required