1

Is there a way to compare pointers in Solidity?

I have two local variables:

uint256[] memory a = new uint256[](256);
uint256[] memory b = a;

If I try a == b I get this compiler error:

TypeError: Operator == not compatible with types uint256[] memory and uint256[] memory

2

One possible solution is to use the eq instruction in inline assembly:

uint256[] memory a = new uint256[](256);
uint256[] memory b = a;
bool aEqualsB;
assembly {
    aEqualsB := eq(a, b)
}
// aEqualsB now contains the value: true

b = new uint256[](256);
assembly {
    aEqualsB := eq(a, b)
}
// aEqualsB now contains the value: false
|improve this answer|||||
  • 1
    I will accept my own workaround as answer until there is a better way. – Jesse Busman Jul 9 '18 at 19:18
  • 1
    There is still no better way, as far as I'm aware. – Jesse Busman Dec 16 '19 at 18:34

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.