title: How does the caller know when there's a Decimal inside a VARIANT?
body: <p>The COM <code>VARIANT</code> type is defined using the <code>tagVARIANT</code> structure like this:</p>
  
  <pre><code>typedef struct tagVARIANT {
    union {
      struct {
        VARTYPE vt;
        WORD    wReserved1;
        WORD    wReserved2;
        WORD    wReserved3;
        union {
          LONGLONG     llVal;
          LONG         lVal;
          BYTE         bVal;
          SHORT        iVal;
          FLOAT        fltVal;
          DOUBLE       dblVal;
          VARIANT_BOOL boolVal;
          VARIANT_BOOL __OBSOLETE__VARIANT_BOOL;
          SCODE        scode;
          CY           cyVal;
          DATE         date;
          BSTR         bstrVal;
          IUnknown     *punkVal;
          IDispatch    *pdispVal;
          SAFEARRAY    *parray;
          BYTE         *pbVal;
          SHORT        *piVal;
          LONG         *plVal;
          LONGLONG     *pllVal;
          FLOAT        *pfltVal;
          DOUBLE       *pdblVal;
          VARIANT_BOOL *pboolVal;
          VARIANT_BOOL *__OBSOLETE__VARIANT_PBOOL;
          SCODE        *pscode;
          CY           *pcyVal;
          DATE         *pdate;
          BSTR         *pbstrVal;
          IUnknown     **ppunkVal;
          IDispatch    **ppdispVal;
          SAFEARRAY    **pparray;
          VARIANT      *pvarVal;
          PVOID        byref;
          CHAR         cVal;
          USHORT       uiVal;
          ULONG        ulVal;
          ULONGLONG    ullVal;
          INT          intVal;
          UINT         uintVal;
          DECIMAL      *pdecVal;
          CHAR         *pcVal;
          USHORT       *puiVal;
          ULONG        *pulVal;
          ULONGLONG    *pullVal;
          INT          *pintVal;
          UINT         *puintVal;
          struct {
            PVOID       pvRecord;
            IRecordInfo *pRecInfo;
          } __VARIANT_NAME_4;
        } __VARIANT_NAME_3;
      } __VARIANT_NAME_2;
      DECIMAL decVal;
    } __VARIANT_NAME_1;
  } VARIANT;
  </code></pre>
  
  <p>Normally when the caller wants to use the data inside a Variant, it uses the <code>VARTYPE vt</code> flag to see what kind of data is stored, and ultimately how those 1s and 0s should be interpreted.</p>
  
  <p>What happens then when a <code>DECIMAL</code> is stored in the Variant; the definition lies outside the <code>struct</code> containing <code>vt</code>, so how does the caller determine whether there's a valid type flag or just some bytes of the Decimal? The Decimal takes <s>12<a href="https://stackoverflow.com/questions/59899919/how-does-the-caller-know-when-theres-a-decimal-inside-a-variant?noredirect=1#comment105927676_59899919">*</a></s> 14 bytes to store and the Variant can hold 16, so possibly this information is leveraged, but isn't what's stored in the spare 2 bytes of the smaller member of a union undefined behaviour?</p>