"Vasileios Zografos" <> wrote in message
news:bdnakv$qbr$...
> Hi, I have the following piece of code which sometimes throws a
> segmentation fault, because this.x, this.y, this.z might be unallocated
> (and it is not possible to initialize them). Its more of a geometric
> problem than programming fault.
Seg-faults during access to data members usually indicates that
the whole object itself has not been allocated adequately.
Does the 'this' pointer happen to be NULL when the segfault occurs?
Maybe what you want to do is a check such as:
if( this==0 ) .... // handle error condition...
It works in practice on some platforms, but is a bad idea in
any case, as this formally leads to undefined behavior.
As others mentioned, it *is* a programming fault to call
an object that hasn't been allocated and constructed.
The design of your code needs to be changed to avoid
such situations.
Feel free to provide more details if you want further guidance.
hth,
--
Ivan Vecerina, Dr. med. <>
http://www.post1.com/~ivec
Soft Dev Manger, XiTact <>
http://www.xitact.com
Brainbench MVP for C++ <>
http://www.brainbench.com