Is this a problem of 'SizeOf' or of the debugger?

Beta Testing discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Is this a problem of 'SizeOf' or of the debugger?

#1 Post by Dany » 18 May 2020 18:21

Hi, the SizeOf(MyRec) gives 20, while the size is obviously only 18 (including the alignment dummy bytes). Are the 2 extra bytes something related to the variable alignment issue (I would myself prefer that the value 18 is given back by the function SizeOf, of course the dummy bytes inserted for alignment have to be counted as they are now).

Thanks in advance.
Capture18-05-2020-19.15.37.jpg
Capture18-05-2020-19.15.37.jpg (207.84 KiB) Viewed 1867 times
The code is the following:

Code: Select all

program Word_Alignment;

{ Declarations section }

Type TArr = Array[5] of byte;

Type Trec = record
    Byte1: byte;
    Word1: word;
    Byte2: byte;
    Dword1: dword;
    Byte3: byte;
    Arr1: TArr;
    end;

var MyRec: TRec;  volatile;
    Siz: byte;

begin
  { Main program }
  Siz := SizeOf(MyRec);
end.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Is this a problem of 'SizeOf' or of the debugger?

#2 Post by filip » 29 May 2020 13:51

Hi Dany,

I see your point, I will consult our developers and get back to you ASAP.

Thanks for the patience.

EDIT:
This is due to the variable alignment, from the help file :
Simple type variables whose size is 2 bytes are set to alignemnt 2, those whose size is 4 bytes and larger are set to alignment 4. Variables of other size are set to alignment 1.
Routines are always set to alignment 4. Only aligned memory access is supported.
Regards,
Filip.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Is this a problem of 'SizeOf' or of the debugger?

#3 Post by Dany » 15 Jun 2021 18:50

filip wrote:
29 May 2020 13:51
Hi Dany,

This is due to the variable alignment, from the help file :
Simple type variables whose size is 2 bytes are set to alignemnt 2, those whose size is 4 bytes and larger are set to alignment 4. Variables of other size are set to alignment 1.
Routines are always set to alignment 4. Only aligned memory access is supported.
Regards,
Filip.
Indeed, all is clear now. Thanks very much.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Post Reply

Return to “mikroPascal PRO for PIC32 Beta Testing”