Forum > FPC development
[solved] Confusing scope(s) for typed constant
TRon:
--- Quote from: Fibonacci on September 25, 2023, 11:15:30 am ---This makes sense, because if you were able to do it, what "Foo" would be? A const, or a procedure?
--- End quote ---
Ofc. it makes sense :). But the ambiguity for (at least) that (specific case) can be solved by using Self to refer to the class/object.
--- Quote from: Fibonacci on September 25, 2023, 11:40:10 am ---'somefunc' will remember 'stringy' value and on each call add another dot to it
--- End quote ---
It is exactly that behaviour that makes me use it (on occasion) :D
It is perhaps because English isn't native for me that I interpret that part of the documentation as "behave and act acting like a global variable" thereby probably missing the nuance of "behaves".
Fibonacci:
--- Quote from: TRon on September 25, 2023, 11:40:26 am ---
--- Quote from: Fibonacci on September 25, 2023, 11:15:30 am ---This makes sense, because if you were able to do it, what "Foo" would be? A const, or a procedure?
--- End quote ---
Ofc. it makes sense. But the ambiguity for (at least) that (specific case) can be solved by using Self to refer to the class/object.
--- End quote ---
And in mode Delphi it works exactly like that. Alternative solution is using the modeswitch DUPLICATELOCALS, which IMHO should be default on for mode ObjFpc
TRon:
--- Quote from: Fibonacci on September 25, 2023, 11:44:09 am ---And in mode Delphi it works exactly like that. Alternative solution is using the modeswitch DUPLICATELOCALS, which IMHO should be default on for mode ObjFpc
--- End quote ---
I can confirm that it works in mode Delphi (as expected) but the duplicatelocals modeswitch doesn't seem to do the trick for me. Tried other modeswitches as well (at least those that seem relevant) to no avail.
btw: Thank you for the response as my initial posted example more or less missed the point.
edit: figured it out. It requires trunk for that to work. Thank you !
tetrastes:
--- Quote from: TRon on September 25, 2023, 11:20:14 am ---I still wonder what is actually meant with "A local typed constant behaves like a global initialized variable" because practice shows it isn't seen by the compiler as a global variable.
--- End quote ---
I think here this means that it is initialized only once. The author of doc forget about different scope. It is analogue of static variable in C.
TRon:
Indeed it seems that author forgot about scope (or that you are not suppose to include/add that yourself when reading the statement from the docs). I get it now thanks to you both.
Navigation
[0] Message Index
[#] Next page
[*] Previous page