[fpc-devel] class constants
Jonas Maebe
jonas.maebe at elis.ugent.be
Mon Oct 19 16:12:23 CEST 2009
On 19 Oct 2009, at 16:18, Peter Popov wrote:
>> An example would be
>> TItemCache = class
>> private
>> const DEFAULT_CACHE_SIZE = 1024;
>> ...
>> end;
>>
>> sure a global value would do, but there is no need for the value to
>> be global.
>
> This is a good example. However, the same paradigm can be achived by
> a function:
>
> function TItemCache.DEFAULT_CACHE_SIZE: Integer;
> begin
> Result := 1024;
> end;
>
> If properly inlined, the compiled code is the same and semantically
> the two are the same.
Except if you want to use the constant in another constant expression
(which is not possible with a function, inlined or not).
Jonas
More information about the fpc-devel
mailing list