0

I am receiving the "stack too deep" error when compiling my smart contract. I know it has to do with too many variables, and I've heard of creating a memory array to "group" variables together. I'm looking for an example of this in a struct that I can follow. I can post code if it would help. Thanks, Rob

1
  • You should post your code. Someone will probably help you sort it out. Aug 1 '18 at 4:02
0

You can do something like this. But you should be aware that using memory is more expensive than simple stack.

pragma solidity ^0.4.0;
contract Ballot {

    struct Voter {
        uint weight;
        bool voted;
        uint8 vote;
        address delegate;
    }

    function foo(bool d) public pure returns (uint) {
        Voter memory votes;
        votes.weight = 123;
        votes.voted = true;
        votes.delegate = msg.sender;
        votes.vote = 1;
        if (d) {
            votes.weight += 11; 
        } else {
            votes.vote = 2;
        }
        return votes.weight + votes.vote;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.