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.

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.