when will the size of an enumerated type change?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

when will the size of an enumerated type change?

Dennis
Type
    TComparisonMode = (cmThisOnly, cmThisAndThat, cmThisOrThat);


TMyClass = class
public
var
    ComparisonMode : TComparisonMode;
end;


I discovered that, the sizeof(ComparisonMode) seem to be different
depending on whether the type TComparisonMode is defined in the same
unit file or in another unit file.

Is that possible?

I cannot create a simple test file to test it because the problem only 
appears in my big project.

Does FPC always produce a 4 byte variable for an enumerated types?

Dennis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: when will the size of an enumerated type change?

Michael Van Canneyt


On Wed, 9 Jan 2019, Dennis wrote:

> Type
>    TComparisonMode = (cmThisOnly, cmThisAndThat, cmThisOrThat);
>
>
> TMyClass = class
> public
> var
>    ComparisonMode : TComparisonMode;
> end;
>
>
> I discovered that, the sizeof(ComparisonMode) seem to be different
> depending on whether the type TComparisonMode is defined in the same
> unit file or in another unit file.
>
> Is that possible?
If the units are compiled using different settings, yes.

>
> I cannot create a simple test file to test it because the problem only 
> appears in my big project.
>
> Does FPC always produce a 4 byte variable for an enumerated types?

No, it depends on the $mode directive and the settings of the packenum directive.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal