Twincat 3 – SizeOf returning wrong structure size

I have a structure, and am trying to get the size of this structure. SizeOf returns 16, but I am expecting 14 as answer.


By using pointers I noticed that there are 2 empty bytes at the end of the structure.

If I replace the UDINT with UINT then the size is correct. If I put the UDINT at the end of the structure, then the two empty bytes are placed after iCrateCnt.

This leads me to believe that the sizeOf is working properly, but for some unknown reason there are two additional bytes placed somewhere in my structure that I am not using.

Why is this happening and how can it be solved?

enter image description here

>Solution :

The pack_mode attribute can be used to eliminate unused bytes in a structure.

Leave a Reply