2

I've run into some odd behavior of solidity. In the following example:

// Omit corner cases for brevity
contract C {
    address[] addrList;

    function addAddr(address addr) {
        addrList.push(addr);
    }

    function deleteAddr(address addr) {

        for(uint256 i = 0; i < addrList.length; i++) {
             if(addr == addrList[i]) {
                 for(uint256 j = i; j < addrList.length; j++) {
                     addrList[j] = addrList[j + 1];
                 }
                 delete addrList[addrList.length - 1];
                 addrList.length--; // <== This gives Error: Expression has to be an lvalue.
             }
        }
    }
}

it cannot resize the length of the array once the value has been deleted. Why can't the length of the address array be decremented?

Deleting integers from an integer array is possible.

2

I tried to execute the code in browser-solidity with a private geth 1.4.10 node and it worked.

Here my receipt:

Result: {
  "blockHash": "0x18f6fc3b76958dcbf841bbbc9d9e039a1920fe68679fbc80fa091f4b0174c73b",
  "blockNumber": 1156,
  "contractAddress": null,
  "cumulativeGasUsed": 21464,
  "from": "0x0fd8cd36bebcee2bcb35e24c925af5cf7ea9475d",
  "gasUsed": 21464,
  "logs": [],
  "root": "94baadfff43ba52cac5cf14f6d43e04351207f8bae1f30503aaced9bc4295e8b",
  "to": "0xa5da304da6eac9cc6ce5292385a396ef8ded4e9a",
  "transactionHash": "0x5f27bc3f984609bc69b59f6eee002e66b9ba8fa698e680fda54dbb7fb04c3d6d",
  "transactionIndex": 0
}
Transaction cost: 21464 gas. 
  • I'm missing something (this is a simplified version of the code). – Sebi Jul 21 '16 at 13:57
  • 1
    I've found the answer here: stackoverflow.com/questions/33839122/… Basically you can't resize memory attributes only storage attributes. – Sebi Jul 21 '16 at 14:15
  • 1
    this I knew but your code was not a Memory thing ;-) – Roland Kofler Jul 21 '16 at 14:24

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.