Hi,
I am facing this weird problem. When the sample pgm given below is compiled with -lpthread
option, the pgm gives seg fault on HP-UX 11iv2
The compiler used is "HP aC++/ANSI C B3910B A.05.50"
The pgm was compiled using - "aCC -lpthread samp.cpp"
Code:
#include <iostream.h>
#include <string>
#define CONSTLM "Error occurred while accessing log directory %s. 1Reason Code = %d. Assuming
default log directory = /opt/newdirecty/log"
class Msg : public exception
{
string m_strMsg;
public:
Msg()
{
}
Msg(const char*p_strMsg, const char *path, int no)
{
char l_str[1024];
memset(l_str,0,1024);
sprintf(l_str,p_strMsg,path,no);
m_strMsg = l_str;
}
void display()
{
string l_str;
l_str ="_";
l_str +=m_strMsg;
l_str +="\n";
printf("Msg2 - %s\n",l_str.c_str());
}
};
class A
{
public:
void ab()
{
try
{
throw Msg(CONSTLM,"/opt/newdirecty/log",2);
}
catch(Msg &m)
{
m.display();
}
}
};
int main()
{
A obj;
obj.ab();
}
When same pgm is compiled without using "-lpthread", it works fine.
The problem seems to occur at display function at Line "l_str +="\n";"
Also, instead of throw Msg obj, if a display func is directly called, it works fine.
It seems to be a problem related to combination of string, throw & lpthread
Has anyone faced such problem before?
Please Help