0

Setting variables like this can pack them into a single slot:

uint128 v1 =1;
uint128 v2 =2;

But does return values also pack in this way? Does

returns (uint128, uint128)

also pack data?

Will experiment it later myself

1 Answer 1

1

Setting variables like this can pack them into a single slot

Your example doesn't work, uint is an alias for uint256, so in that specific example both variable use a full slot each. Maybe it was a typo and you meant uint128 ?

But does return values also pack in this way ?

No. Input and outputs are abi encoded (see the documentation), that is, padded to 32 bytes each with some caveats for dynamic types. Thus, the following function would return two 32 bytes values :

function test() public view returns (uint128, uint128) {
  uint128 a = 1;
  uint128 b = 2;

  return (a, b);
}

I hope that answers your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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