Recent

Author Topic: Typed constants  (Read 2351 times)

fdsingleton

  • New Member
  • *
  • Posts: 31
Typed constants
« on: October 21, 2017, 10:39:55 pm »
I am taking my simulation system from Laz1.2.6/FPC 2.6.4 to the new Laz with FPC 3.0.2.  Simple problems work on it but if I go to a more complicated test problem with identical source FPC 2.6.4 and 3.0.2 it does not work on the newer one.  There is some discussion of typed constants being unchangeable in the newer one and changeable in the older.  There is some discussion of {$J+} and {$J-} but I cannot find this mentioned anywhere else in regular documentation or Lazarus option menus.  I use -Mdelphi and have always assumed that typed numerical or boolean contants could be changed.  What is the deal here?

fdsingleton

  • New Member
  • *
  • Posts: 31
Re: Typed constants
« Reply #1 on: October 21, 2017, 10:54:34 pm »
I should mention that everything works when run from the IDE but when compiled and linked separately from the IDE the simple problem works and the more complex one says it compiles and links OK (a lot of pre-compiled units involved) but the calculations go wrong with FPC 3.0.2 (and not FPC 2.6.4).

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Typed constants
« Reply #2 on: October 21, 2017, 11:53:12 pm »
{$J} is documented, for example here
The default is {$J+} for compatibility with Turbo Pascal, though many people wish the default were otherwise.
Global typed constants are initialised once at program start and local typed constants once at first call of the routine routine, and in the default {J+} state then behave like initialised variables and retain whatever value is subsequently assigned to them.

We cannot tell if you have found a bug in the documented behaviour without you showing a compilable example that shows a difference from what is expected.

fdsingleton

  • New Member
  • *
  • Posts: 31
Re: Typed constants
« Reply #3 on: October 22, 2017, 11:19:33 pm »
Thank you for clarifying that the default has not changed.   I am working on an application which started with Turbo Pascal and has gone through a lot of changes since.  There is a lot of code and I think I must search for something that is not initialized.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: Typed constants
« Reply #4 on: October 22, 2017, 11:40:21 pm »
If it is a difference between fpc versions, then start by checking how your code works in both versions when compiled with -O- (with no optimizations)

Some bugs in user code only manifest when compiled with optimizations.

If it is an uninitialized value, then compile with -gtttt ( 1 to 4 "t", each t makes a difference)

Other useful settings
-gh  and Environment HEAPTRC="keepreleased"
 may need lots of memory....

or if you are on linux: valgrind

 

TinyPortal © 2005-2018