I don't know if this is a quirk in the remix IDE or something solidity does itself, but I've found something interesting and would like to know why it occurs.

I have a struct x in a contract Y which has two fields:

Struct X {
   address owner;
   address renter;

Now, when I initialize the struct by calling the function createX() in the remix IDE:

function createX() public {
   X storage x;
   x.owner = msg.sender;

The renter address field gets the value of the contract address Y

example of address field

Why does this happen? I expected the field to equal the zero address.


1 Answer 1


The Solidity compiler should emit a warning for this.

X storage x; declares an uninitialized storage reference. That means x points to slot 0 in storage. When you store msg.sender in x.owner, it overwrites whatever was in slot 0 (the first state variable you declared). x.renter, since you haven't modified it, should still hold whatever your second declared state variable was.

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.