Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Diffrerent output of the same program on HP aCC and Linux (Intel/g++) (http://www.velocityreviews.com/forums/t955637-diffrerent-output-of-the-same-program-on-hp-acc-and-linux-intel-g.html)

Alex Vinokur 12-19-2012 08:38 AM

Diffrerent output of the same program on HP aCC and Linux (Intel/g++)
 
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 +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 g++ compiler
Compilation:
> 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 below.

Any suggestions?

Thanks.

Alex

// ========== File aaa21.cpp: BEGIN ==========
#include <cstring>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <string>
#include <strstream> // deprecated
#include <sstream>




// ========================
#define TRACE std::cout << "\nLine-" << __LINE__ << ": --- " << __FUNCTION__ << " ---" << std::endl
#define START std::cout << "\nLine-" << __LINE__ << ": >>> START " << __FUNCTION__ << " <<<" << std::endl
#define FINISH std::cout << "Line-" << __LINE__ << ": <<< FINISH " << __FUNCTION__ << " >>>" << std::endl << std::endl
#define SHOW(x) std::cout << "[ Line-" << __LINE__ << ", " << __FUNCTION__ << "] " << #x << " = <" << x << ">" << std::endl

// ---------------------------
void showCompilerInfo(std::ostream& o_stream)
{
o_stream << "Compiler: ";
#if (defined __hpux && defined __HP_aCC)
o_stream << "HP C/aC++ "
<< __HP_aCC;

#elif (defined __INTEL_COMPILER)
o_stream << "Intel(R) C++ Intel(R) 64 Compiler, Version "
<< __INTEL_COMPILER;

#elif (defined __GNUC__ && !defined __INTEL_COMPILER)
o_stream << "GNU g++, Version "
<< __GNUC__;
#ifdef __GNUC_MINOR__
o_stream << "." << __GNUC_MINOR__;

#ifdef __GNUC_PATCHLEVEL__
#if __GNUC_PATCHLEVEL__
o_stream << "." << __GNUC_PATCHLEVEL__;

#endif // #ifdef __GNUC_PATCHLEVEL__
#endif // #if __GNUC_PATCHLEVEL__
#endif // #ifdef __GNUC_MINOR__


#else
#error Unknown compiler
#endif

o_stream << std::endl << std::flush;
}

// -------------
char* pStrStream = 0;
char* pStringStream = 0;

// -------------
static void putToStrStream(std::ostream& i_stream, const char* i_pText)
{
START;

SHOW(pStrStream);
SHOW(strlen(pStrStream));
SHOW(i_pText);
SHOW(strlen(i_pText));

i_stream << i_pText;

SHOW(pStrStream);
SHOW(strlen(pStrStream));

FINISH;

}

// -------------
static void putToStringStream(std::ostream& i_stream, const char* i_pText)
{
START;

SHOW(pStringStream);
SHOW(strlen(pStringStream));
SHOW(i_pText);
SHOW(strlen(i_pText));

// i_stream.clear();
// i_stream.seekp(0, std::ios::beg);
i_stream << i_pText;
// i_stream << std::ends;

SHOW(pStringStream);
SHOW(strlen(pStringStream));

FINISH;
}

// ----------------
void doStrStream(const char* i_pText, std::size_t i_size)
{

START;

SHOW(i_size);

std::strstream stream(pStrStream, i_size);
SHOW(stream.rdbuf()->pcount());
SHOW(stream.str());

putToStrStream(stream, i_pText);
SHOW(stream.rdbuf()->pcount());

FINISH;
}

// ----------------
void doStringStream(const char* i_pText, std::size_t i_size)
{

START;

SHOW(i_size);

std::stringstream stream;
stream.rdbuf()->pubsetbuf(pStringStream, i_size);
// stream.rdbuf()->str("");

SHOW(stream.tellp());
SHOW(stream.str().size());
SHOW(stream.rdbuf()->str().size());
SHOW(stream.rdbuf()->in_avail());

SHOW(stream.str());
SHOW(stream.str().c_str());
SHOW(stream.str().data());
putToStringStream(stream, i_pText);
SHOW(stream.str());
SHOW(stream.str().c_str());
SHOW(stream.str().data());

SHOW(stream.tellp());
SHOW(stream.str().size());
SHOW(stream.rdbuf()->str().size());
SHOW(stream.rdbuf()->in_avail());

FINISH;
}



// ------------
int main()
{

system ("uname -a");
showCompilerInfo(std::cout);
std::cout << "Data Model: " << (sizeof(void*) * CHAR_BIT) << " bits" << std::endl;

pStrStream = new char [100];
pStringStream = new char [100];

memset (pStrStream, 'P', 100);
pStrStream[70] = 0;
memset (pStringStream, 'Q', 100);
pStringStream[90] = 0;


TRACE;
doStrStream("ABCDEF", 45);
doStrStream("XYZ", 25);


TRACE;
doStringStream("abcdef", 45);
doStringStream("xyz", 25);


// ------------------
delete[] pStrStream;
delete[] pStringStream;

return 0;
}
// ========== File aaa21.cpp: END ==========



// ========== Log HP aCC: BEGIN ==========

HP-UX hpx418 B.11.23 U ia64 1139467043 unlimited-user license
Compiler: HP C/aC++ 62501
Data Model: 64 bits

Line-166: --- main ---

Line-100: >>> START doStrStream <<<
[ Line-102, doStrStream] i_size = <45>
[ Line-105, doStrStream] stream.rdbuf()->pcount() = <0>
[ Line-106, doStrStream] stream.str() = <PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>

Line-59: >>> START putToStrStream <<<
[ Line-61, putToStrStream] pStrStream = <PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-62, putToStrStream] strlen(pStrStream) = <70>
[ Line-63, putToStrStream] i_pText = <ABCDEF>
[ Line-64, putToStrStream] strlen(i_pText) = <6>
[ Line-68, putToStrStream] pStrStream = <ABCDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-69, putToStrStream] strlen(pStrStream) = <70>
Line-71: <<< FINISH putToStrStream >>>

[ Line-109, doStrStream] stream.rdbuf()->pcount() = <6>
Line-111: <<< FINISH doStrStream >>>


Line-100: >>> START doStrStream <<<
[ Line-102, doStrStream] i_size = <25>
[ Line-105, doStrStream] stream.rdbuf()->pcount() = <0>
[ Line-106, doStrStream] stream.str() = <ABCDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>

Line-59: >>> START putToStrStream <<<
[ Line-61, putToStrStream] pStrStream = <ABCDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-62, putToStrStream] strlen(pStrStream) = <70>
[ Line-63, putToStrStream] i_pText = <XYZ>
[ Line-64, putToStrStream] strlen(i_pText) = <3>
[ Line-68, putToStrStream] pStrStream = <XYZDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-69, putToStrStream] strlen(pStrStream) = <70>
Line-71: <<< FINISH putToStrStream >>>

[ Line-109, doStrStream] stream.rdbuf()->pcount() = <3>
Line-111: <<< FINISH doStrStream >>>


Line-171: --- main ---

Line-118: >>> START doStringStream <<<
[ Line-120, doStringStream] i_size = <45>
[ Line-126, doStringStream] stream.tellp() = <0>
[ Line-127, doStringStream] stream.str().size() = <0>
[ Line-128, doStringStream] stream.rdbuf()->str().size() = <0>
[ Line-129, doStringStream] stream.rdbuf()->in_avail() = <0>
[ Line-131, doStringStream] stream.str() = <>
[ Line-132, doStringStream] stream.str().c_str() = <>
[ Line-133, doStringStream] stream.str().data() = <>

Line-78: >>> START putToStringStream <<<
[ Line-80, putToStringStream] pStringStream = <QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-81, putToStringStream] strlen(pStringStream) = <90>
[ Line-82, putToStringStream] i_pText = <abcdef>
[ Line-83, putToStringStream] strlen(i_pText) = <6>
[ Line-90, putToStringStream] pStringStream = <abcdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-91, putToStringStream] strlen(pStringStream) = <90>
Line-93: <<< FINISH putToStringStream >>>

[ Line-135, doStringStream] stream.str() = <abcdef>
[ Line-136, doStringStream] stream.str().c_str() = <abcdef>
[ Line-137, doStringStream] stream.str().data() = <abcdef>
[ Line-139, doStringStream] stream.tellp() = <6>
[ Line-140, doStringStream] stream.str().size() = <6>
[ Line-141, doStringStream] stream.rdbuf()->str().size() = <6>
[ Line-142, doStringStream] stream.rdbuf()->in_avail() = <6>
Line-144: <<< FINISH doStringStream >>>


Line-118: >>> START doStringStream <<<
[ Line-120, doStringStream] i_size = <25>
[ Line-126, doStringStream] stream.tellp() = <0>
[ Line-127, doStringStream] stream.str().size() = <0>
[ Line-128, doStringStream] stream.rdbuf()->str().size() = <0>
[ Line-129, doStringStream] stream.rdbuf()->in_avail() = <0>
[ Line-131, doStringStream] stream.str() = <>
[ Line-132, doStringStream] stream.str().c_str() = <>
[ Line-133, doStringStream] stream.str().data() = <>

Line-78: >>> START putToStringStream <<<
[ Line-80, putToStringStream] pStringStream = <abcdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-81, putToStringStream] strlen(pStringStream) = <90>
[ Line-82, putToStringStream] i_pText = <xyz>
[ Line-83, putToStringStream] strlen(i_pText) = <3>
[ Line-90, putToStringStream] pStringStream = <xyzdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-91, putToStringStream] strlen(pStringStream) = <90>
Line-93: <<< FINISH putToStringStream >>>

[ 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>
Line-144: <<< FINISH doStringStream >>>

// ========== Log HP aCC: END ==========



// ========== Log Linux g++: BEGIN ==========

Linux illin793 2.6.32-279.5.2.el6.x86_64 #1 SMP Tue Aug 14 11:36:39 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
Compiler: GNU g++, Version 4.4.6
Data Model: 64 bits

Line-166: --- main ---

Line-100: >>> START doStrStream <<<
[ Line-102, doStrStream] i_size = <45>
[ Line-105, doStrStream] stream.rdbuf()->pcount() = <0>
[ Line-106, doStrStream] stream.str() = <PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>

Line-59: >>> START putToStrStream <<<
[ Line-61, putToStrStream] pStrStream = <PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-62, putToStrStream] strlen(pStrStream) = <70>
[ Line-63, putToStrStream] i_pText = <ABCDEF>
[ Line-64, putToStrStream] strlen(i_pText) = <6>
[ Line-68, putToStrStream] pStrStream = <ABCDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-69, putToStrStream] strlen(pStrStream) = <70>
Line-71: <<< FINISH putToStrStream >>>

[ Line-109, doStrStream] stream.rdbuf()->pcount() = <6>
Line-111: <<< FINISH doStrStream >>>


Line-100: >>> START doStrStream <<<
[ Line-102, doStrStream] i_size = <25>
[ Line-105, doStrStream] stream.rdbuf()->pcount() = <0>
[ Line-106, doStrStream] stream.str() = <ABCDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>

Line-59: >>> START putToStrStream <<<
[ Line-61, putToStrStream] pStrStream = <ABCDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-62, putToStrStream] strlen(pStrStream) = <70>
[ Line-63, putToStrStream] i_pText = <XYZ>
[ Line-64, putToStrStream] strlen(i_pText) = <3>
[ Line-68, putToStrStream] pStrStream = <XYZDEFPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPP>
[ Line-69, putToStrStream] strlen(pStrStream) = <70>
Line-71: <<< FINISH putToStrStream >>>

[ Line-109, doStrStream] stream.rdbuf()->pcount() = <3>
Line-111: <<< FINISH doStrStream >>>


Line-171: --- main ---

Line-118: >>> START doStringStream <<<
[ Line-120, doStringStream] i_size = <45>
[ Line-126, doStringStream] stream.tellp() = <0>
[ Line-127, doStringStream] stream.str().size() = <45>
[ Line-128, doStringStream] stream.rdbuf()->str().size() = <45>
[ Line-129, doStringStream] stream.rdbuf()->in_avail() = <45>
[ Line-131, doStringStream] stream.str() = <QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-132, doStringStream] stream.str().c_str() = <QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-133, doStringStream] stream.str().data() = <QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>

Line-78: >>> START putToStringStream <<<
[ Line-80, putToStringStream] pStringStream = <QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-81, putToStringStream] strlen(pStringStream) = <90>
[ Line-82, putToStringStream] i_pText = <abcdef>
[ Line-83, putToStringStream] strlen(i_pText) = <6>
[ Line-90, putToStringStream] pStringStream = <abcdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-91, putToStringStream] strlen(pStringStream) = <90>
Line-93: <<< FINISH putToStringStream >>>

[ Line-135, doStringStream] stream.str() = <abcdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-136, doStringStream] stream.str().c_str() = <abcdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-137, doStringStream] stream.str().data() = <abcdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-139, doStringStream] stream.tellp() = <6>
[ Line-140, doStringStream] stream.str().size() = <45>
[ Line-141, doStringStream] stream.rdbuf()->str().size() = <45>
[ Line-142, doStringStream] stream.rdbuf()->in_avail() = <45>
Line-144: <<< FINISH doStringStream >>>


Line-118: >>> START doStringStream <<<
[ Line-120, doStringStream] i_size = <25>
[ Line-126, doStringStream] stream.tellp() = <0>
[ Line-127, doStringStream] stream.str().size() = <25>
[ Line-128, doStringStream] stream.rdbuf()->str().size() = <25>
[ Line-129, doStringStream] stream.rdbuf()->in_avail() = <25>
[ Line-131, doStringStream] stream.str() = <abcdefQQQQQQQQQQQQQQQQQQQ>
[ Line-132, doStringStream] stream.str().c_str() = <abcdefQQQQQQQQQQQQQQQQQQQ>
[ Line-133, doStringStream] stream.str().data() = <abcdefQQQQQQQQQQQQQQQQQQQ>

Line-78: >>> START putToStringStream <<<
[ Line-80, putToStringStream] pStringStream = <abcdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-81, putToStringStream] strlen(pStringStream) = <90>
[ Line-82, putToStringStream] i_pText = <xyz>
[ Line-83, putToStringStream] strlen(i_pText) = <3>
[ Line-90, putToStringStream] pStringStream = <xyzdefQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ>
[ Line-91, putToStringStream] strlen(pStringStream) = <90>
Line-93: <<< FINISH putToStringStream >>>

[ 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>
Line-144: <<< FINISH doStringStream >>>

// ========== Log Linux g++: END ==========



Bart van Ingen Schenau 12-19-2012 10:11 AM

Re: Diffrerent output of the same program on HP aCC and Linux
 
On Wed, 19 Dec 2012 00:38:58 -0800, Alex Vinokur wrote:

> 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 +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 g++ compiler
> Compilation:
>> 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 below.
>
> Any suggestions?


In the program you use
> stream.rdbuf()->pubsetbuf(pStringStream, i_size);

to try to change the underlying buffer used by the stringstream.
According to the C++03 standard, pubsetbuf(s, n) calls setbuf(s, n).
The effects of calling setbuf of a stringbuf are implementation defined,
so each compiler can choose whatever behaviour they think is sane (as
long as it is consistent and documented).
You will have to check the compiler documentation, but from the obtained
results it seems that GCC regards the original contents of the buffer to
be present in the stream (ready for being read), while HP aCC regards the
buffer as being empty.
Both are equally valid.

>
> Thanks.
>
> Alex
>

Bart v Ingen Schenau

Alex Vinokur 12-19-2012 06:31 PM

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


"Bart van Ingen Schenau" wrote in message
news:kas3sk$ugt$1@dont-email.me...

[snip]
> Both are equally valid.

[snip]

Thank you.



All times are GMT. The time now is 10:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.