Can a function have more than one return value?

Can a function have more than one return value?

Is there a work around?

Maybee in Assembler to return both, R0 & R1.

:-)

Is this silly?

Parents
  • Can a function have more than one return value?

    In C ? No.

    Is there a work around?

    In C ? Yes. Return a pointer to a structure, or pack several small datatypes into one large datatype, or use global variables. The first is probably the cleanest way to do it, the other two might have their uses in certain situations.

    Maybee in Assembler to return both, R0 & R1.

    In assembler, all bets are off. As long as the caller (which should also be in assembly) knows what the exit status of the function is (which registers are changes etc), you can do whatever you want in assembly. Just be sure to meticulously document everything, and don't ever call such a function from any language that has particular calling conventions.

Reply
  • Can a function have more than one return value?

    In C ? No.

    Is there a work around?

    In C ? Yes. Return a pointer to a structure, or pack several small datatypes into one large datatype, or use global variables. The first is probably the cleanest way to do it, the other two might have their uses in certain situations.

    Maybee in Assembler to return both, R0 & R1.

    In assembler, all bets are off. As long as the caller (which should also be in assembly) knows what the exit status of the function is (which registers are changes etc), you can do whatever you want in assembly. Just be sure to meticulously document everything, and don't ever call such a function from any language that has particular calling conventions.

Children
No data
More questions in this forum