User Tools

Site Tools


ddsf:public:guidebook:06_append:glossary:u:union

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ddsf:public:guidebook:06_append:glossary:u:union [2020/09/24 13:30]
murphy
ddsf:public:guidebook:06_append:glossary:u:union [2021/07/14 16:45] (current)
murphy ↷ Links adapted because of a move operation
Line 1: Line 1:
 ===== Union ===== ===== Union =====
-[[ddsf:private:cookbook:​06_append:​glossary| Return to Glossary ]]+[[ddsf:public:guidebook:​06_append:​glossary:start| Return to Glossary ]]
  
 A **Union** is like a data structure in that it generally has several fields, all of which are public by default. Unlike a struct, however, only one of the fields is used at any given time. In other words, it is a structure that allows the same storage space to be used to store values of different data types at different times. Thus it is necessary, and the programmer'​s responsibility,​ to keep track of what is actually stored in the union at any given time. A **Union** is like a data structure in that it generally has several fields, all of which are public by default. Unlike a struct, however, only one of the fields is used at any given time. In other words, it is a structure that allows the same storage space to be used to store values of different data types at different times. Thus it is necessary, and the programmer'​s responsibility,​ to keep track of what is actually stored in the union at any given time.
  
-**Unions** can be used to conserve memory when a structure is needed in which several pieces of information of different types must be represented but only one will be used at a time, as when the components of a [[ddsf:private:cookbook:​06_append:​glossary:​c:​container|container]] must contain values of differing data types.+**Unions** can be used to conserve memory when a structure is needed in which several pieces of information of different types must be represented but only one will be used at a time, as when the components of a [[ddsf:public:guidebook:​06_append:​glossary:​c:​container|container]] must contain values of differing data types.
  
 Source: [[http://​cs.smu.ca/​~porter/​csc/​common_341_342/​notes/​union.html | Union ]] Source: [[http://​cs.smu.ca/​~porter/​csc/​common_341_342/​notes/​union.html | Union ]]
  
ddsf/public/guidebook/06_append/glossary/u/union.1600968638.txt.gz · Last modified: 2020/09/24 13:30 by murphy