Solved

Memory implications and runtime behaviour

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

635 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