Currently i try to enforce some stricter coding style ( class like encapsulating in structs , usage of public/private etc…). But now i come to a simple curiosity
let’s asume the following, hypothetical struct definition:
struct Test ( varA=5, function print1=( print varA ), varA=10, function print2=( print varA ) )
so now when i create an instance of struct Test and call the functions, i get this output
t=Test() -- create an instance t.varA -- puts out: 10 , as expected t.print1() -- prints: 5 ??? t.print2() -- this prints the expected value: 10
Why the hell does print1() not print the currently set value ? Is this really depening on the order of variable definition ? To my understanding, print1() should do as its function body tells it to do, print the current value of variable varA, which it apparently does not
any hints or insights ?
this is maybe the relevant part in the help docs, but honestly, i can’t see this to be a reason for the above behavior…
Local functions defined in structures are not stored in every instance of the structure. The local function is stored once in the structure definition and references to them in the instances refer to their definitions in the structure definition.