[Ethereum] Passing struct types to libraries by reference, internal and external calls

solidity

I need some clarification on internal and external library calling in relation to whether a struct is passed by reference or copied or something else.

In this following library example, L_i() is internal, is compiled into the derived contract's bytecode and called by jump. The struct parameter _s is passed by reference and so _s.i will be updated contract wide (so to speak).

library lib_internal {
    struct LStruct { uint i; }
    function L_i (LStruct storage _s) internal {
        _s.i++;
    }

In the following external instance, and this is where I need help, is _s still passed by reference but within the context of the contract or is it copied in the DELEGATECALL data to L_i()?

library lib_external {
    struct LStruct { uint i; }
    function L_i (LStruct storage _s) public {
        _s.i++;
    }

Best Answer

Finally found the answer in the docs...right at the bottom.

The only situation where no copy will be performed is when storage reference variables are used.

Related Topic