Hi
I'm getting this error. I would like help knowing how deep "too deep" is - i.e. is there a rule of thumb for how many local variables are allowed? I've been constructing a number of structs with references and mappings to other structs, up to 4 deep. e.g. categories[categoryID].nominees[nomineeID].user.externalUserID. I have not been trying to recompile as I go, so I now need to refactor across the contract.
There are a couple of references to the error on Google, but none definitive on when it will occur.
James
0 ·
Comments
Any and all suggestions for improving ANY aspect of this (from a code/language/structure p.o.v) gratefully received.
I've stripped out all of the registration code etc.
Just so I'm clear, if I have a function with 1 uint parameter "_in" and 1 uint return value "_out", and have a local uint variable declared inside the function, then that is 3 out of a max of 16. And if I have a reference to a variable held at the contract level (i.e. outside the function) then it needs a further 2, i.e. 5 out of 16.
I still need to read up on storage references and packed storage and the 2 stack slots bit.
James
If this limit keeps on being a problem after the change I proposed above, it might be worthwhile considering moving some of the variables to memory.
My own impression is that (again, after the change which will reduce the stack load to about half in your example) this limit should not be a real problem in reasonably written code.
Please correct me if I am making wrong assumptions there.
Concerning your second comment: This is about storage, not about the stack. Variables are not tightly packed on the stack, i.e. even a bool variable will take a full stack position.