Structs as function parameters

jwgcarlylejwgcarlyle Member Posts: 29
edited July 2015 in Solidity
Hi

I have some code that does not compile :
contract TestContract {
	struct Cat1 { mapping (uint => uint) test; }
	struct Cat2 { uint test; }

	function fun1 (Cat1 c) internal { return; }
}

If I change this to call fun1 with Cat2, all is OK.

I'm trying to reconcile this with the documentation - the Solidity Features page says this
"Structs can be passed around as function arguments, be returned from functions and created in memory."

But the Solidity Tutorial says this:
"conversions between these data locations are performed automatically by the compiler. Sometimes, this is still not possible, i.e. mappings cannot reside in memory (as their size is unknown)".

So should the Solidity Features page be updated to say "Structs can be passed as function arguments, but only if they don't contain mappings"? Apologies if I have the wrong end of the stick.

James
Post edited by StephanTual on

Comments

  • chrisethchriseth Member Posts: 170 ✭✭✭
    The features wiki is only meant as a short changelog and does not always describe all edge-cases of a change. The tutorial is the official documentation / reference, also because previous entries into the features page are not updated if they are altered at a later time.
  • jwgcarlylejwgcarlyle Member Posts: 29
    Thanks @chriseth, I'm busy refactoring code and trying to experiment with what is possible, and was just looking for confirmation.
Sign In or Register to comment.