I have 2 structs like this:

struct A { ... }
struct B { A a; }

A[] aa;
B[] bb;

function createB(uint256 aIndex) {
  A storage a = aa[aIndex];
  B memory b = B({a: a});


Instances of A stored in array and in

I have couple of questions about it:

  1. Why doesn't works explicit declaration of a inside B as storage, i.e. A storage a doesn't compile?
  2. Am I right that anyway I'll have b.a as storage ref, not as copy of original A instance?

1 Answer 1


1) Sorry, but why do you need explicit declaration of a as storage? Why not use:

function createB(uint256 aIndex) {
  B memory b = B({a: aa[aIndex]});


2) No. Either way you will store copy.

  • Because I have 2 arrays of different structs and want to be able to refers from one to another without copying.
    – Alex G.P.
    Apr 10, 2018 at 4:05
  • It is sad that one storage struct unable to keep storage reference to another, just tested it. Thanks.
    – Alex G.P.
    Apr 10, 2018 at 4:57

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .