473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

An allocated variable returning by a fuction is unallocated automatically ?


I would like to know, if an allocated variable returning by a fuction is
unallocated automatically ?

If no how to proceed ?

Best regards

------------------------------------------------------------------------

In my case, I want to return aa. After the call of polit, is aa is
unallocated automatically ?

char * polit(char *expressions)
{
..
..
..
aa = (char *)malloc(strlen(Result)*sizeof(char)+1);
..
..
..
return(aa);
}


Jul 19 '05 #1
2 2234
On Mon, 14 Jul 2003 12:19:34 +0200, "orion30" <or*****@ifrance.com> wrote:

I would like to know, if an allocated variable returning by a fuction is
unallocated automatically ?
No.
If no how to proceed ?
Use smart-pointers. Use std::auto_ptr for simple
transfer of ownership (deallocation responsibility).
Use boost::shared_ptr for a pointer that isn't
necessarily "owned" by a single something.

std::auto_ptr lives in standard header <memory>.

boost::shared_ptr: go to [http://www.boost.org].
In my case, I want to return aa. After the call of polit, is aa is
unallocated automatically ?

char * polit(char *expressions)
{
.
.
.
aa = (char *)malloc(strlen(Result)*sizeof(char)+1);
Should be

aa = new char[ strlen(Result) + 1];

in C++.

return(aa);
}


Jul 19 '05 #2
0On Mon, 14 Jul 2003 10:27:52 GMT, al***@start.no (Alf P. Steinbach) wrote:
On Mon, 14 Jul 2003 12:19:34 +0200, "orion30" <or*****@ifrance.com> wrote:

I would like to know, if an allocated variable returning by a fuction is
unallocated automatically ?


No.
If no how to proceed ?


Use smart-pointers. Use std::auto_ptr for simple
transfer of ownership (deallocation responsibility).
Use boost::shared_ptr for a pointer that isn't
necessarily "owned" by a single something.

std::auto_ptr lives in standard header <memory>.

boost::shared_ptr: go to [http://www.boost.org].
In my case, I want to return aa. After the call of polit, is aa is
unallocated automatically ?

char * polit(char *expressions)
{
.
.
.
aa = (char *)malloc(strlen(Result)*sizeof(char)+1);


Should be

aa = new char[ strlen(Result) + 1];

in C++.

return(aa);
}

Sorry, I didn't think. You're probably trying to achieve something
else than the code indicates. In that case, use std::string.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: orion30 | last post by:
I would like to know, if an allocated variable returning by a fuction is unallocated automatically ? If no how to proceed ? Best regards ...
31
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there is not standard method to "(...) query the...
8
by: ranjeet.gupta | last post by:
Dear All I am not able o understand the exact number of bytes allocation done by the two fucntion given below, It is said that the fuction Condition_String1 allocates the 240 bytes while...
148
by: onkar | last post by:
Given the following code & variable i . int main(int argc,char **argv){ int i; printf("%d\n",i); return 0; } here i is allocated from bss or stack ?
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
11
by: mast2as | last post by:
This question has been posted to this forum before and I read the thread but found that the answers were perhaps imcomplete, so I am trying again. Whenever I am creating objects I would like to...
7
by: Serpent | last post by:
The C-FAQ describes some techniques here: http://c-faq.com/aryptr/dynmuldimary.html I was using something slightly different from the C-FAQ and I was wondering if it was legal. Say I want a...
4
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.