hello,
i searching for days for an Segmentation fault.
What i ve done:
i try:
- valgrind
- gdb
- comment the most c++ code out
my problem, if i comment out one more header i got an Segmentation fault.
i try different headers, always the same.
-> some more code -> crash (which header i comment out, is equal)
i try to rebuild the error, create an new project, copy the source code, run...
all okay. i can not replicate the error, with "new" source code. *argh*
my cood looks like
<code>
#include <iostream>
#include <vector>
class interface{
public:
void init(void);
private:
std::vector<unsigned char> m_data;
};
class m{
public:
void init(void);
private:
minterface m_i;
};
void m::init(void)
{
m_i.init(this);
}
int main() {
m a;
a.init();
return 0;
}
</code>
if i got an segmentation fault the address from the variable m_ptr is too close to the m_data,
check my gdb out:
(gdb) break minterface::init
(gdb) r
(gdb) print m_data
$1 = std::vector of length 0, capacity 0
(gdb) print &m_data
$2 = (std::vector<unsigned char, std::allocator<unsigned char> > *) 0xbefffc8c
(gdb) print m_ptr
$3 = (m_ptr *) 0x0
(gdb) print &m_ptr
$4 = (m_ptr **) 0xbefffc8c
The code that you have posted does not contain any header files.
If the segfault only happens when you change the code, never after a fresh build, then maybe there is something wrong with how your build process is set up. When a header file is modified all .cpp files that includes that header file (either directly or indirectly through another header) needs to be recompiled.