Recent

Author Topic: How to declare uninitialized writable constant (static var) ?  (Read 4524 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11530
  • FPC developer.
Re: How to declare uninitialized writable constant (static var) ?
« Reply #15 on: April 10, 2024, 02:59:28 pm »
Afaik the const business is old TP, and delphi uses VAR with initialization for static vars.

But mode objFPC used that syntax for initialized local variables.

Solution: use $mode delphi.

440bx

  • Hero Member
  • *****
  • Posts: 4198
Re: How to declare uninitialized writable constant (static var) ?
« Reply #16 on: April 10, 2024, 03:40:48 pm »
Solution: use $mode delphi.
but, even in Delphi mode a var in a function or procedure is a local whose value, unlike a static, isn't persistent across calls, therefore that's not a solution.

Did I misunderstand what you were saying ?
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14625
  • Sensorship about opinions does not belong here.
Re: How to declare uninitialized writable constant (static var) ?
« Reply #17 on: April 10, 2024, 04:03:17 pm »
Afaik the const business is old TP, and delphi uses VAR with initialization for static vars.

But mode objFPC used that syntax for initialized local variables.

Solution: use $mode delphi.
Nope, does not work. You are right about writeable consts stemming from TP times, but not about initialized vars in local context.
Therefor I suggest to change the writeable const to static or static var, because that is what a writeable const actually means. It is all about local, not global....
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11530
  • FPC developer.
Re: How to declare uninitialized writable constant (static var) ?
« Reply #18 on: April 10, 2024, 04:21:59 pm »
Yup, I was wrong. I don't use static variables, and it shows :-)
« Last Edit: April 10, 2024, 04:58:29 pm by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 14625
  • Sensorship about opinions does not belong here.
Re: How to declare uninitialized writable constant (static var) ?
« Reply #19 on: April 10, 2024, 04:55:52 pm »
You are not alone...See Rika's comment on the bug tracker...
That's two old hands making the same mistake... :D ;D 8-)
[edit]
I think, after analysis of the compiler code regarding this, it should be possible to use static as a decorator for var, so static var. That is probably the preferred syntax.
I need help, but that would be my second compiler patch...
Just static seems easier, but static var is more expressive.
Let me know what you think. Better to discuss it here than immediately on the bug tracker ( although I put in a feature request already)
It seems I already have two supporters for the feature, maybe even three....
« Last Edit: April 10, 2024, 06:17:19 pm by Thaddy »
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

 

TinyPortal © 2005-2018