AnsweredAssumed Answered

Union array issue

Question asked by AngusZhao on Jul 19, 2011
Latest reply on Jul 20, 2011 by Yaniv.Sapir

VDSP++5.0 udpate 9 :


In union , I have one array . Below is example :


typedef union  _nld_control_union
{
#ifdef HMI_CFG_TEXT
nld_Editbox     cEdit;
#endif
#ifdef HMI_CFG_CHECKBOX
nld_Checkbox    cCheck;
#endif
#ifdef  HMI_CFG_BUTTON
nld_Button      cButton;
#endif
#ifdef  HMI_CFG_OPTION
nld_RadioButton cRadion;
#endif
#ifdef  HMI_CFG_LABEL
nld_Label       cLabel;
#endif
#ifdef HMI_CFG_LISTBOX
nld_Listbox     cList;
#endif
#ifdef  HMI_CFG_COMBOBOX
nld_Combobox    cCombo;
#endif
#ifdef  HMI_CFG_PROGRESSBAR
nld_Progressbar cProgress;
#endif
#ifdef HMI_CFG_SCROLLBAR
nld_VScrollbar  cVScrollbar;
nld_HScrollbar  cHScrollbar;
#endif
#ifdef HMI_CFG_LINE
nld_Line        cLine;
#endif
#ifdef  HMI_CFG_FRAME
nld_Frame       cFrame;
#endif
#ifdef  HMI_CFG_PICTUREBOX
nld_Picturebox  cPicture;
#endif
#ifdef HMI_CFG_IMAGE
nld_Image       cImage;
#endif
#ifdef  HMI_CFG_ANIMATE
nld_Animate     cAnimate;
#endif   

}nld_control_union,*NLD_CONTROL_UNION_PTR;

In this union, nld_Editbox、nld_Checkbox are all defined struct type.

 

============================================================

We shall try to get union result through sizeof .  For example:

sizeof(nld_control_union)

The result is zero .

 

Define union array :

nld_control_union nld_CMem_Block[10];

Then we shall do below work to assign value  :

nld_control_union *mptr=&(nld_CMem_Block[9]);

The result is :

  mptr=nld_CMem_Block+9

 

I think the right result should be :   mptr=nld_CMem_Block+9*(nld_control_union)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

Why ? and would you pls advise what's root reason?

Outcomes