 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
sorcer Guest
|
Posted: Tue Dec 20, 2005 11:13 am Post subject: declaration then append OK? |
|
|
Can I do the following:
....
std::string NewString;
....
NewString += (const char *)SomeChars;
Is it OK to append to the string as the first "assignment"? Windows and
Linux are OK (well, so far), but Solaris is breaking, and I'm not sure
if this is the cause, due to stack corruption.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
benben Guest
|
Posted: Tue Dec 20, 2005 1:38 pm Post subject: Re: declaration then append OK? |
|
|
sorcer wrote:
| Quote: | Can I do the following:
...
std::string NewString;
...
NewString += (const char *)SomeChars;
|
If SomeChars isn't a const char* (for you have casted it to such type)
perhaps you can tell us what it is.
| Quote: |
Is it OK to append to the string as the first "assignment"? Windows and
Linux are OK (well, so far), but Solaris is breaking, and I'm not sure
if this is the cause, due to stack corruption.
|
By "to append to the string as the first assignment" do you mean:
a. std::string NewString = "blah";or
b. std::string NewString; NewString = "blah"; or
c. std::string NewString; NewString += "blah"; ?
I doubt your problem has anything to do with the operating system.
Perhaps it is the library that broke.
Regards,
Ben
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
hroussel_at_delphes.com@h Guest
|
Posted: Tue Dec 20, 2005 2:34 pm Post subject: Re: declaration then append OK? |
|
|
Hi!
You ask:
| Quote: | Can I do the following:
...
std::string NewString;
...
NewString += (const char *)SomeChars;
|
Without a sample that compile, the only answer is:
Maybe.
The fact that it crash on solaris is a good indication that your code
has a problem.
Wonixen
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ulrich Eckhardt Guest
|
Posted: Tue Dec 20, 2005 2:34 pm Post subject: Re: declaration then append OK? |
|
|
sorcer wrote:
| Quote: | std::string NewString;
...
NewString += (const char *)SomeChars;
Is it OK to append to the string as the first "assignment"?
|
Yes.
| Quote: | Windows and Linux are OK (well, so far), but Solaris is breaking,
|
All three are operating systems and there are compilers out there that run
on all three of them. In order to really specify the system you're on, you
should mention the compiler/version plus the OS/version, but I doubt that
that is the problem here.
| Quote: | and I'm not sure if this is the cause, due to stack corruption.
|
If the code compiles with the cast removed, it is probably ok, but with the
cast it is impossible to tell. It might also make a difference what
'SomeChars' really is. Otherwise, a small testprogram that demonstrates the
faulty behaviour would be necessary.
As a general rule, never use casts unless you have to. If you get errors or
warnings which you don't understand, casting is wrong, even if the errors
or warnings disappear.
Uli
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Lars Tetzlaff Guest
|
Posted: Tue Dec 20, 2005 7:02 pm Post subject: Re: declaration then append OK? |
|
|
sorcer schrieb:
| Quote: | Can I do the following:
...
std::string NewString;
...
NewString += (const char *)SomeChars;
Why do you need the '(const char *)'? |
What is 'SomeChars'?
Lars
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Paul Floyd Guest
|
Posted: Wed Dec 21, 2005 3:27 am Post subject: Re: declaration then append OK? |
|
|
On 20 Dec 2005 06:13:12 -0500, sorcer <sklekas (AT) websense (DOT) com> wrote:
| Quote: | Can I do the following:
...
std::string NewString;
...
NewString += (const char *)SomeChars;
Is it OK to append to the string as the first "assignment"? Windows and
|
I've seen some problems with Sun Studio 11 and initialization from a
temporary, like
std::string newString = aString + anotherString;
when using optimize options.
My guess is that a patch is in the pipeline.
A bientot
Paul
--
Paul Floyd http://paulf.free.fr (for what it's worth)
Surgery: ennobled Gerald.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Paul Floyd Guest
|
Posted: Thu Dec 22, 2005 3:26 am Post subject: Re: declaration then append OK? |
|
|
On 20 Dec 2005 22:27:06 -0500, Paul Floyd <root (AT) 127 (DOT) 0.0.1> wrote:
[snip - problem with initialization from a temporary on Solaris]
| Quote: | My guess is that a patch is in the pipeline.
|
... no sooner said than done, it seems. There are now a couple of
patches for the common compiler backend and C++ compiler that seem to
fix the problem.
A bientot
Paul
--
Paul Floyd http://paulf.free.fr (for what it's worth)
Surgery: ennobled Gerald.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|