Skip to content

Instantly share code, notes, and snippets.

@clesaege
Created December 27, 2023 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clesaege/2bd6722cd3c82ebaf74dd6d0d916b95c to your computer and use it in GitHub Desktop.
Save clesaege/2bd6722cd3c82ebaf74dd6d0d916b95c to your computer and use it in GitHub Desktop.
Push VS Assign
pragma solidity >=0.7;
contract Test {
struct S {uint a; uint b; uint c;}
S[] ss;
function f() external {
ss.push(S({a:5,b:0,c:2}));
}
function g() external {
S storage s = ss.push();
s.a=5;
s.b=0;
s.c=2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment