title: How is the union used in this OpenCV library?
body: <p>I am busy trying to learn about OpenCV, but there is one part I do not understand. This is probably an easy question to answer, but I am nonetheless stuck and would appreciate your answer. In OpenCV, a matrix is implemented as follows:</p>
  
  <pre><code>typedef struct CvMat {
    int type;
    int step;
    int* refcount;
    union {
      uchar* ptr;
      short* s;
      int* i;
      float* fl;
      double* db;
    } data;
    union {
      int rows;
      int height;
    };
    union {
      int cols;
      int width;
    };
  } CvMat;
  </code></pre>
  
  <p>As I understand it, a union means that <code>int rows</code> and <code>int height</code>, for example, share the same memory location. If that is so, I would expect rows and height to always have the same value. That would then mean we could only have square matrices, which I do not think is the case in OpenCV. So how can we have two different values for rows and height even though it's a union? Could someone please enlighten me as to how this structure works?</p>
  
  <p>Thank you very much!</p>