7

Answer of this question (https://ethereum.stackexchange.com/a/3590/4575) says that: "I am not allowed to return dynamic arrays from Solidity functions yet."

On the other hand, Solidity supports functions with multiple return values. How can I return multiple strings from a contract function?

[Q] Is there any limitation for the number of the return values in one function call. Such as, could I return N (for example N=1000) number of values or even more in one function call?

function getData() constant returns (bytes32, bytes32, bytes32, bytes32, 
                                     bytes32, bytes32, bytes32, ...) {
    bytes32 a = "a";
    bytes32 b = "b";
    bytes32 c = "c";
    bytes32 d = "d";
    bytes32 e = "e";
    bytes32 f = "f";
    bytes32 g = "g";
    return (a, b, c, d, e, f, g, ...);
}

Thank you for your valuable time and help.

alper
  • 8,395
  • 11
  • 63
  • 152

2 Answers2

8

In practice, the call stack imposes a limitation in current implementations.

The following contract will face a 'Stack too deep' compiler error.

pragma solidity ^0.4.3;

contract Test {
    function getData() constant returns (bytes32, bytes32, bytes32, bytes32,
                                     bytes32, bytes32, bytes32, bytes32,
                                     bytes32, bytes32, bytes32, bytes32,
                                     bytes32, bytes32, bytes32) {                                         

        return ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o");                                         
    }
}

Browser Solidity:

https://ethereum.github.io/browser-solidity/#gist=ac9812a045a41fd4168f2e352732962d

Gist URL:

https://gist.github.com/anonymous/ac9812a045a41fd4168f2e352732962d

Derek Tiffany
  • 341
  • 2
  • 5
4

According to the Solidity grammar the amount of return values are infinite:

FunctionDefinition = 'function' Identifier? ParameterList
                     ( FunctionCall | Identifier | 'constant' | 'external' | 'public' | 'internal' | 'private' )*
                     ( 'returns' ParameterList )? Block
[...]

ParameterList = '(' ( TypeName Identifier? (',' TypeName Identifier?)* )? ')'

This is shown by the * in (',' TypeName Identifier?)* which means 1..infitinty in the grammar notation.
Of course the capacity of computers put some natural limitation to it, that can be only explored empirically.

Roland Kofler
  • 11,638
  • 3
  • 44
  • 83