?
Solved

Memory implications and runtime behaviour

Posted on 2002-03-29
5
Medium Priority
?
180 Views
Last Modified: 2010-04-02
const char* strName="";
strName=getstr(var);
Func(strName);


const char* strName="none";
strName=getstr(var);
Func(strName);

What are the implications of this code w.r.t memory and runtime behaviour

Getting a runtime assertion.
Could this part be responsible?

Better way of doing it.
NOTE: Func cannot take a typecasted const char* as input.
0
Comment
Question by:bitnal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 150 total points
ID: 6905818
If you which to modify the data that is being pointed to by strName, then try the following instead;

char strName[] = "none";


0
 

Author Comment

by:bitnal
ID: 6905931
Wont that create a problem in calling the function func().
This is a 3-party function and I cannot change it.
secondly, Will this format not require any allocation and freeing of memory?

thanks.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6905968
>>Wont that create a problem in calling the function func().
What type does the Func take?

>>secondly, Will this format not require any allocation >>and freeing of memory?
No.
0
 
LVL 30

Expert Comment

by:Axter
ID: 6905978
The code you posted is a little confusing.

What is "var"?  What type is it, and where is it coming from?

If var is a non-const variable, then you can change your code to the following:

char* strName=getstr(var);
Func(strName);


With out seeing the rest of your code, it's hard to tell what you really need.

Please post more code.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6956305
Dear bitnal

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "Axter"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question