Returning multiple values from a C function

前端 未结 11 990
醉话见心
醉话见心 2021-01-18 08:05

Important: Please see this very much related question: Return multiple values in C++.

I\'m after how to do the same thing in ANSI C? Would you use a

11条回答
  •  逝去的感伤
    2021-01-18 09:02

    I would pass the address to a struct. If the information to be returned isn't complex, then just passing in the addresses to the values would work too.

    Personally, it really comes down to how messy the interface would be.

    void SomeFunction( ReturnStruct* myReturnVals )
    {
      // Fill in the values
    }   
    
    // Do some stuff    
    ReturnStruct returnVals;
    SomeFunction( &returnVals);    
    // Do more stuff
    

提交回复
热议问题