Topics | Search Log Out | Register | Edit Profile
Hide Clipart | Banned/Unbanned User Log | Moderator Login History | Thread Delete/Move Log | Last 30 mins | 1 | 2
Calling c/c++ experts

Chalanachithram.com DB » New TF Industry Related » Archive through August 24, 2015 » Calling c/c++ experts « Previous Next »
Author Message
 

Myselfme
Junior Artist
Username: Myselfme

Post Number: 273
Registered: 04-2011
Posted From: 107.77.87.88

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, August 24, 2015 - 04:20 pm:       

Ownership transferred from function*
 

Analog
Side Hero
Username: Analog

Post Number: 4149
Registered: 05-2008
Posted From: 129.110.242.50

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, August 24, 2015 - 04:19 pm:       

top(int hfhf...)
{

char* carray
carray = calloc(num,sizeof(char));

modify_carray(xxx,xxx,carray)
use_carray(xx,xxx,carray)

free(carray);
}

modify_carray(int XX....,char* carray)
{

// write to carray

}

use_carray(....,char* carray)
{
// read carray
}
 

Myselfme
Junior Artist
Username: Myselfme

Post Number: 272
Registered: 04-2011
Posted From: 107.77.87.88

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, August 24, 2015 - 04:19 pm:       

Is it interview question?

If yes, they is a possibility that they are getting into discussion on smart pointer, since the ownership is transferred to a function, use the shared_ptr in the main function, you can return unique_ptr from function

I may be wrong
 

Ysr2009
Side Hero
Username: Ysr2009

Post Number: 2467
Registered: 03-2014
Posted From: 129.135.0.21

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, August 24, 2015 - 04:00 pm:       

A( char **sCharOut)
{
....
(*sCharOut) = (char*) malloc(iLength * sizeof(char));
// Fill sCharOut
}

B()
{
char *sString=NULL;
A( &sString );
free( sString );
}

 

Maverick
Legend
Username: Maverick

Post Number: 57974
Registered: 01-2008
Posted From: 108.171.130.188

Rating: N/A
Votes: 0 (Vote!)

Posted on Monday, August 24, 2015 - 03:56 pm:       

what is the best way to return char* to the calling function?after a malloc of a local variable, need to return back to calling function..in that case who frees it and how to return?
Happy Vizag

Add Your Message Here
Post:
Bold text Italics Underline Create a hyperlink Insert a clipart image HASH(0x9ee4334){Movie Clipart}
Show / hide regular icons selection options

Click on following links to open cliparts by Alphabetical Order

 A   B   C   D   E   F   G   H   I   J   K   L   M  

N   O   P   Q   R   S   T   U   V   W   X   Y   Z  

Show / Hide Filmy icons selection options

Click on following links to open cliparts by Alphabetical Order

  A   B   C   D   E   F   G   H   I   J   K   L   M  

N   O   P   Q   R   S   T   U   V   W   X   Y   Z  

Username: Posting Information:
This is a public posting area. Enter your username and password if you have an account. Otherwise, enter your full name as your username and leave the password blank. Your e-mail address is optional.
Password:
E-mail:
Options: Enable HTML code in message
Automatically activate URLs in message
Action: