Can someone from QSSL comment since 10.6 is the QNX4 compiler. Will there be
a fix available for this or are we stuck?
I tried your code under 10.6 and got the following results:
Kind of scary.
So I assume that since this produces the expected results under 11.0 that it
is indeed a compiler bug with Watcom 10.6 and that this code is acceptable.
0x9d40.XString( const char* -><- )
0x94d0.~XString()
0x9da8.XString( const char* -><- )
0x9da8.XString& operator = ( const XString& ->0x9d40<- )
0x9da8.~XString()
“Kon Tantos” <ksoft1@attglobal.net> wrote in message
news:3A09A967.FF8F310F@attglobal.net…
If you are using the String class in the Watcom library, you are
probably seeing aString being created for operator =().As a checktTry running the code below, which uses a dummy String class.
When compiled & run (as DOS16 or Win32 console app) with v11a, The code
below produces the output:XString( const char* -><- )
XString( const char* -><- )
XString& operator = ( const XString& -><- )
~XString()
~XString()
Code:// testxx.cpp
#include <iostream
#include <assert.h
#include <conio.h
#include <string.htypedef unsigned int uint;
class XString
{
public:
XString( const char* str_ = “” );
XString( const XString& str_ );
~XString();
XString& operator = ( const XString& str_ );private:
char* str;
};XString::XString( const char* str_)
: str(0)
{
cout << (void*) this << “.XString( const char* ->” << str_ << “<- )\n”;
str = new char[strlen(str_)];
strcpy( str, str_ );
}XString::XString( const XString& str_ )
: str(str_.str)
{
cout << (void*) this << “.XString( const XString& str_ ->” << (void*)
&str_ << “<- )\n”;
}XString::~XString()
{
cout << (void*) this << “.~XString()\n”;
delete [] str;
}XString&
XString::operator = ( const XString& str_ )
{
cout << (void*) this << “.XString& operator = ( const XString& ->”
(void*) &str_ << “<-
)\n”;
char* tmp = new char[strlen(str_.str)];
delete [] str;
str = tmp;
return *this;
}class Test
{
public:
Test(const XString& stringId = “”);
virtual ~Test();private:
XString itsXStringId;
};// Test.cpp
Test::Test(const XString& stringId)
itsXStringId = stringId;
}Test::~Test()
{
}test1()
{
Test aTest;
}int
main()
test1();getch(); return 0;
}“Brown, Richard” wrote:
I have run across the following code fragment and it appears to be
faulty
under the 10.6 compiler. Can someone tell me is this is code is assuming
too
much or should it work? I don’t get any warnings at -w4.First here are some assumptions. Let’s assume that String class has a
constructor that accepts a character buffer.// Test.h
class Test
{public:
Test(const String& stringId = “”);
virtual ~Test();private:
String itsStringId;
};// Test.cpp
Test::Test(const String& stringId)
{
itsStringId = stringId;
}Test::~Test()
{
}// some othe module
Test aTest; // default constructorWhat I get throught the debugger is the following sequence:
- a String is created using the constructor that accpets a character
buffer. It is constructed with “”.- the String created in (1) is destroyed
- the Test constructor is called with a reference to the String created
in (1) but destroyed in (2)- a String is create for the Test object using default constructors
- the assignment is tried and dies a horrible death.
Is this the correct operation? Or should the tempory string created in
(1) not be destoryed until after the Test constructor returns?
- Richard
–
Regards
Kon Tantos
ksoft1@attglobal.net > or > kon.tantos@tafe.nsw.edu.au