Operating System - HP-UX
1755763 Members
2627 Online
108838 Solutions
New Discussion

Diffrerent output of the same program on HP aCC and Linux (Intel/g++) for std::stringstream

 
SOLVED
Go to solution
AlexVi2
Occasional Advisor

Diffrerent output of the same program on HP aCC and Linux (Intel/g++) for std::stringstream

Hi,

While migratining from deprecated std::strstream to std::stringstream we are faced with some problem related to std::stringstream.

The same program produces different output on HP aCC and on Intel/g++ compilers on Linux.

 

 

Here is some fragment of different outputs.

 

HP aCC

Compilation:

> aCC aaa21.cpp

> aCC +DD64 aaa21.cpp

 

[ Line-135, doStringStream] stream.str() = <xyz>

[ Line-136, doStringStream] stream.str().c_str() = <xyz>

[ Line-137, doStringStream] stream.str().data() = <xyz>

[ Line-139, doStringStream] stream.tellp() = <3>

[ Line-140, doStringStream] stream.str().size() = <3>

[ Line-141, doStringStream] stream.rdbuf()->str().size() = <3>

[ Line-142, doStringStream] stream.rdbuf()->in_avail() = <3>

 

 

Linux Intel/g++ compilers

> icpc  aaa21.cpp

> g++  aaa21.cpp

 

[ Line-135, doStringStream] stream.str() = <xyzdefQQQQQQQQQQQQQQQQQQQ>

[ Line-136, doStringStream] stream.str().c_str() = <xyzdefQQQQQQQQQQQQQQQQQQQ>

[ Line-137, doStringStream] stream.str().data() = <xyzdefQQQQQQQQQQQQQQQQQQQ>

[ Line-139, doStringStream] stream.tellp() = <3>

[ Line-140, doStringStream] stream.str().size() = <25>

[ Line-141, doStringStream] stream.rdbuf()->str().size() = <25>

[ Line-142, doStringStream] stream.rdbuf()->in_avail() = <25>

 

 

The program and logs attached.

 

Any suggestions?

Thanks.

 

Alex

 

 

3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: Different output of the same program on HP aCC and Linux (Intel/g++) for std::stringstream

The 98 C++ Standard 27.7.1.3(16) says basic_stringbuf::setbuf is implementation defined.

As documented in  basic_stringbuf(3C++), RW's basic_stringbuf::setbuf copies the current contents (empty) into the new buffer and uses the current pointer relative offsets.

 

(Contrary to the documentation, the buffer isn't owned, if not NULL.)

 

You may try this workaround:

#ifdef WORK
                std::string str_tmp(pStringStream, i_size);
                std::stringstream stream(str_tmp);
#else
                std::stringstream stream;
                stream.rdbuf()->pubsetbuf(pStringStream, i_size);
#endif

AlexVi2
Occasional Advisor

Re: Different output of the same program on HP aCC and Linux (Intel/g++) for std::stringstream

Dennis, thank you.

Dennis Handly
Acclaimed Contributor

Re: Different output of the same program on HP aCC and Linux (Intel/g++) for std::stringstream

>thank you.

 

If you're happy please also assign kudos.