M
Mark
Hi all,
I am making a program which will run on Linux/Unix and Win platforms.
The Win part is completed (compiled with MinGW) and I am concentrating
now on the *NIX one.
I am trying to use standard library as much as possible, but as you
may know there are specific tasks that relies only on OS capabilities.
Basically, apart from main and various threads/child processes, the
program consists of a few classes.
Let's consider two of them and call them CControlClass and
CLoggerClass.
The implementation is very similar both in Win and *NIX.
CControlClass incorporates CLoggerClass this way.
*LoggerObj is declared as private member of CControlClass.
(CLoggerClass *LoggerObj)
CControlClass::CControlClass()
{ readConfFile("somefile.conf"); }
int CControlClass::readConfFile(const char * somefile){
//do some parsing
LoggerObj=new CLoggerClass("some_log_file.log");
LoggerObj->writeLog(some_const_int,some_char_array_or_stringstream)
}
int CControlClass::functionOne()
{
//something
LoggerObj->writeLog(...,...)
}
//main.cpp
int main(int argc, char** argv)
{
CControlClass *ControlObj=new CControlClass();
ControlObj->functionOne();
}
In win environment, program runs really good.
On Linux (g++ 4.1) it compiles, it will write the log related to
readConfFile but when functionOne calls the Logger (called from main),
a private variable of CLoggerClass (needed to tailor detalization of
output) is not anymore referenced. That causes a segmentation fault.
I was able to recover from SEGFAULT, putting LoggerObj=new
CLoggerClass("some_log_file.log") into the constructor of
ControlClass... but it will not write anything when called by
functionOne,Two,Three... and when called by readConfFile, it will
write the log into the configuration file
Can you please explain what's the matter?
I 'd like to understand why such a big difference exists in Linux and
Win variable scope in Standard C++.
Thanks,
Mark
I am making a program which will run on Linux/Unix and Win platforms.
The Win part is completed (compiled with MinGW) and I am concentrating
now on the *NIX one.
I am trying to use standard library as much as possible, but as you
may know there are specific tasks that relies only on OS capabilities.
Basically, apart from main and various threads/child processes, the
program consists of a few classes.
Let's consider two of them and call them CControlClass and
CLoggerClass.
The implementation is very similar both in Win and *NIX.
CControlClass incorporates CLoggerClass this way.
*LoggerObj is declared as private member of CControlClass.
(CLoggerClass *LoggerObj)
CControlClass::CControlClass()
{ readConfFile("somefile.conf"); }
int CControlClass::readConfFile(const char * somefile){
//do some parsing
LoggerObj=new CLoggerClass("some_log_file.log");
LoggerObj->writeLog(some_const_int,some_char_array_or_stringstream)
}
int CControlClass::functionOne()
{
//something
LoggerObj->writeLog(...,...)
}
//main.cpp
int main(int argc, char** argv)
{
CControlClass *ControlObj=new CControlClass();
ControlObj->functionOne();
}
In win environment, program runs really good.
On Linux (g++ 4.1) it compiles, it will write the log related to
readConfFile but when functionOne calls the Logger (called from main),
a private variable of CLoggerClass (needed to tailor detalization of
output) is not anymore referenced. That causes a segmentation fault.
I was able to recover from SEGFAULT, putting LoggerObj=new
CLoggerClass("some_log_file.log") into the constructor of
ControlClass... but it will not write anything when called by
functionOne,Two,Three... and when called by readConfFile, it will
write the log into the configuration file
Can you please explain what's the matter?
I 'd like to understand why such a big difference exists in Linux and
Win variable scope in Standard C++.
Thanks,
Mark