Solved

Memory implications and runtime behaviour

Posted on 2002-03-29
5
176 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
  • 3
5 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 50 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

828 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