Solved

Memory implications and runtime behaviour

Posted on 2002-03-29
5
177 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

739 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