I am encountering a strange behaviour in solaris10. I have a C++ code which is working fine when I am compiling it in 32bit mode. But when I a compile it in 64bit mode I am facing the errors. My class has string variables(For using string I have coded
#include <string>
using namespace std;)
I have initialized the variables to NULL in the constructor and then I have checked the length of the variable (variable.length()). It returns a garbage value. This behaviour is only in 64bit mode. The same code works fine in 32bit mode.
Can anyone pls give me a clue of how to solve this error.
In the class I have a string variable "mstrHeader". I have initialized the variable to null. In the constructor at line no 13 I am trying to print the length of the variable (mstrHeader.length()). As the variable is initialized to null the length should be 0. But the length is printed as 58.
I am working on solaris 5.10 environment and using CC compiler(Sun C++ 5.8). Compiler flags are "-xarch=v9 -xildoff -mt -D${PRODUCT} -DSOLARIS -DBT_UNIX -DBT_SOLARIS".
CAccOverviewMpbx::CAccOverviewMpbx(const CMergeModule* pmmModule,
const CAbstractMergeJob& amjMergeJob) :
mstrHeader(""),CGenericMerge(pmmModule, amjMergeJob)
{
char* pchFunctionName = (char*) "CAccOverviewMpbx::CAccOverviewMpbx";
//initialises the variables
wDocSequence = 0;
// added to increase the doc sequence of temp files
wDocSeqTemp = 0;
fIsHeaderSaved = true;
fIsTrailerSaved = true;
printf("%d\t%s\t%d\t**%s**\n",mstrHeader.length(),__FILE__,__LINE__,mstrHeader.c_str());fflush(stdout);
DEBUG_TRACE;
// invlkes the sorting method by passing the sort key details
CSortConfig* pscSortCfg = new CSortConfig(SK_POS_ACC_OVERVIEW_MPBX, false);
if(!pscSortCfg)
{
throw CError(BMB_HARD_OTHER, ERR_MSG_MEM_ALLOC_FAILED);
}
CMergePass* pmpMrgPass = new CMergePass(pscSortCfg, 0);
if(!pmpMrgPass)
{
throw CError(BMB_HARD_OTHER, ERR_MSG_MEM_ALLOC_FAILED);
}
mplMergePasses.push_back(pmpMrgPass);
}
Above is the code. In the initialization section I have initialized mstrHeader variable to "". I am facing the issue only in 64bit. The code actually does not initialize the variable. But the behaviour was good in 32bit. And the error was generated in 64bit. Then I have initialized it to zero as there is a condition which passes only if the length is zero. For the length to be zero I have initialized it to null(""). Its of no use as it is retrieving a junk value.
Yeah you are right regarding the initialization. We are acutally no doing it in 32bit mode. Still it was working fine as the default constructor was doing the initialization. But it is not the case in 64bit env. Though we are trying to initialize it to null we are still facing the issue.