[fpc-devel] Typed constants question

J. Gareth Moreton gareth at moreton-family.com
Sat Jul 28 17:30:48 CEST 2018


 Given I want to be conservative with pure functions so it's
near-impossible to write something that breaks the compiler or cause
unexpected behaviour in the compiled binary, I'll treat the accessing of
such a constant as "impure" for reasons of safety.  My work-in-progress
already detects accessing a non-local variable, and this also covers typed
constants, and will remove the 'pure' flag and throw a compiler warning in
this case.

 Because I'm the developer of this feature, I can't guarantee that I won't
overlook something when it comes to writing unit tests.  I'll probably be
relying on you guys to push the compiler and the 'pure' feature to breaking
point!

 Gareth aka. Kit

 On Sat 28/07/18 16:01 , marcov at stack.nl (Marco van de Voort) sent:
 In our previous episode, J. Gareth Moreton said: 

 > For a more fundamental question... why are typed and untyped constants 
 > treated differently? 

 Turbo Pascal allowed to write them, depending on a switch. $J. 
 Delphi adds {$writeableconst on} iirc. 

 But even when this is off, you can't be sure it is on in a different
module, 
 so exported constants can never be folded in. (except of course as a
global 
 optimizations) 

 I guess for a local (implementation) constant this could be checked? 

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180728/a3ae4ea4/attachment.html>


More information about the fpc-devel mailing list