Click here to Skip to main content
15,913,115 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: differentiating between literal strings and char pointers Pin
dburns3-Aug-07 6:22
dburns3-Aug-07 6:22 
GeneralRe: differentiating between literal strings and char pointers Pin
led mike3-Aug-07 7:16
led mike3-Aug-07 7:16 
GeneralRe: differentiating between literal strings and char pointers Pin
David Crow3-Aug-07 7:18
David Crow3-Aug-07 7:18 
GeneralRe: differentiating between literal strings and char pointers Pin
led mike3-Aug-07 7:15
led mike3-Aug-07 7:15 
QuestionRe: differentiating between literal strings and char pointers Pin
David Crow3-Aug-07 5:10
David Crow3-Aug-07 5:10 
AnswerRe: differentiating between literal strings and char pointers Pin
dburns3-Aug-07 5:43
dburns3-Aug-07 5:43 
AnswerRe: differentiating between literal strings and char pointers Pin
cp98763-Aug-07 18:30
cp98763-Aug-07 18:30 
GeneralRe: differentiating between literal strings and char pointers Pin
dburns4-Aug-07 4:05
dburns4-Aug-07 4:05 
Smile | :) Kind of funny you should suggest that, because that's almost exactly what we have today. Once our string type has copied data from a buffer, then it is ref-counted to avoid further copies. We have a means to specify that the input string is a literal quoted string, in which case no copy of the string data is made at all (and ref-counting is not needed).

However in most cases programmers seem to use the version that copies string data even when they're supplying a literal quoted string. No reason other than they have other things on their mind when writing code, and don't seem to remember such details.

So my goal was to detect this and either automatically be more efficient, or give them a compiler error that forces them to use the more efficient version.

As an update I've found I can use "const" to detect the use of a non-literal buffer in some cases, but not all. For example:

char buff[100];<br />
...<br />
StringClass s1(buff); // Works: will use the non-const constructor and will copy.<br />
const char* ptr = ...; // possibly points at some local temp buffer<br />
StringClass s2(ptr); // Can't distinguish between this case...<br />
StringClass s3("hello"); //... and this case


So I would like to distinguish between the s2 and the s3 case (the s2 case should be copied since there's no telling where the pointer is pointing, and the s3 case should not be copied). I don't think C++ is going to let me do that.

Thanks for the ideas...
Questionproblem with radio button and UpdateData Pin
m.dietz3-Aug-07 4:13
m.dietz3-Aug-07 4:13 
AnswerRe: problem with radio button and UpdateData Pin
led mike3-Aug-07 4:52
led mike3-Aug-07 4:52 
GeneralRe: problem with radio button and UpdateData Pin
m.dietz5-Aug-07 20:11
m.dietz5-Aug-07 20:11 
GeneralRe: problem with radio button and UpdateData Pin
led mike6-Aug-07 5:29
led mike6-Aug-07 5:29 
AnswerRe: problem with radio button and UpdateData Pin
David Crow3-Aug-07 5:07
David Crow3-Aug-07 5:07 
GeneralRe: problem with radio button and UpdateData Pin
m.dietz5-Aug-07 20:28
m.dietz5-Aug-07 20:28 
GeneralRe: problem with radio button and UpdateData Pin
David Crow6-Aug-07 2:56
David Crow6-Aug-07 2:56 
GeneralRe: problem with radio button and UpdateData Pin
m.dietz6-Aug-07 20:43
m.dietz6-Aug-07 20:43 
AnswerRe: problem with radio button and UpdateData Pin
Hans Dietrich3-Aug-07 7:57
mentorHans Dietrich3-Aug-07 7:57 
GeneralRe: problem with radio button and UpdateData [modified] Pin
m.dietz5-Aug-07 20:20
m.dietz5-Aug-07 20:20 
QuestionRetrieve the length of an int Pin
Perspx3-Aug-07 4:02
Perspx3-Aug-07 4:02 
AnswerRe: Retrieve the length of an int Pin
Rage3-Aug-07 4:11
professionalRage3-Aug-07 4:11 
GeneralRe: Retrieve the length of an int Pin
Perspx3-Aug-07 4:14
Perspx3-Aug-07 4:14 
GeneralRe: Retrieve the length of an int Pin
David Crow3-Aug-07 4:22
David Crow3-Aug-07 4:22 
GeneralRe: Retrieve the length of an int Pin
LordMarv3-Aug-07 4:34
LordMarv3-Aug-07 4:34 
AnswerRe: Retrieve the length of an int Pin
David Crow3-Aug-07 4:12
David Crow3-Aug-07 4:12 
GeneralRe: Retrieve the length of an int Pin
Perspx3-Aug-07 4:15
Perspx3-Aug-07 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.