Home » Developing U++ » U++ Developers corner » C strings
Re: C strings [message #5712 is a reply to message #5693] |
Tue, 10 October 2006 21:38   |
Shire
Messages: 41 Registered: September 2006 Location: Russia, Yamal peninsula
|
Member |
|
|
Quote: | char * is used in chances are that string itself will be supplied as constant or other char * (avoiding performance and code size loss of char * -> String conversion) AND there is no further string length testing (or when it is negligible performance wise).
|
Not in all cases. For example,
void CodeEditor::Enclose(const char *c1, const char *c2)
{
int l, h;
if(!GetSelection(l, h))
return;
Insert(l, WString(c1));
Insert(h + strlen(c1), WString(c2));
ClearSelection();
SetCursor(h + strlen(c1) + strlen(c2));
}
Calculating the size of const string is already overhead.
For non-const strings, determination of the end of string by zero terminator is unsafe, because it may be lost, and work with this string can make security hole.
I know and understand, that removing C-like strings is huge work (and code works without it, really? ), but IMHO, if you attempted on STL, you can make library safer and faster.
|
|
|
Goto Forum:
Current Time: Fri Jun 06 21:21:21 CEST 2025
Total time taken to generate the page: 0.03609 seconds
|