Thread: geting multiple output from a function

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    14

    geting multiple output from a function

    How can I get multiple output from a function?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Maybe BRING what you want into the function, via pointer - then make your changes it to, and there's nothing that need be returned.

    Or return a pointer to an array of something

    Or return a pointer to a struct with all the struct members you need.

    Sound OK to you?

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    14
    the function is:
    Code:
    bool CLA ( bool x0 , bool x1 , bool x2 , bool x3 , bool y0 , bool y1 , bool y2 , bool y3 , bool y4 , bool cn)
    {
    
    	bool  c0 , c1 , c2 , co , s0 , s1 , s2 , s3;
    	
    	c0 = ( x0 & y0 ) | ( ( x0 ^ y0 ) & cn );
    	c1 = ( x1 & y1 ) | ( ( x1 ^ y1 ) & c0 );
    	c2 = ( x2 & y2 ) | ( ( x2 ^ y2 ) & c1 );
    	co = ( x3 & y3 ) | ( ( x3 ^ y3 ) & c2 );
    	
    	s0 = ( ( x0 ^ y0 ) ^ cn );
    	s1 = ( ( x1 ^ y1 ) ^ c0 );
    	s2 = ( ( x2 ^ y2 ) ^ c1 );
    	s3 = ( ( x3 ^ y3 ) ^ c2 );
    	
    	// I want to return s3, s2, s1, s0
    	
    	
    }

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Looks like a natural to bring in the s[] array into the function. Then don't worry about a return at all, there's no return needed.

    s[0] = s0;
    s[1] = s1;
    //etc.

    You're very brave to have both a c0 and a co variable, in the same function.

    Truth be told, I would think about using arrays for lots of these other bool variables, as well.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    14
    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM