Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Wrong structure size / sizeof() returns too big value

$
0
0

Hi,

one of my structures comes with a too big size although I'm already packed the alignment to 1:

#pragma PACK(1)

struct posframe
{
   unsigned short x,y,z;
};

struct freqframe
{
   unsigned int period;  // divider value for EHRPWMPWMOpFreqSet(pwmFreq); calulated based on frequency of 10MHz
   unsigned short pulse; // counter value for turning pulse off for EHRPWMLoadCMPA(CMPAVal); maximum size is period-2
};

struct mframe // mark frame, sent to device
{
   unsigned char mtype;
   union
   {
      struct posframe  pos;
      struct freqframe freq;
      unsigned int     value;
   } d;
};

When I do a sizeof(struct posframe) the returned size is 6 (which is correct).

When I do a sizeof(struct freqframe) the returned size is 6 (which is correct too).

But when I do a sizeof(struct mframe) the returned value is 9 instead of 7.

Any idea why mframe is too big?


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>