 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
helmut zeisel Guest
|
Posted: Fri May 07, 2004 2:40 pm Post subject: Re: Zugriff auf double bewirkt segmentation fault |
|
|
Markus Dehmann wrote:
| Quote: | PS: Compiler g++ 3.3.1
|
Verschweigst Du uns was?
Bei mir (auch gcc 3.3.1 / Linux Kernel 2.4.21-xfs) läuft das problemlos:
#include <cmath>
#include <iostream>
using namespace std;
typedef double doubleType;
const doubleType log0 = log(0.0);
class test_class
{
doubleType prob;
public:
inline bool is_null() const {
cerr << "Entering" << endl;
bool ret = prob == log0;
cerr << "Exiting" << endl;
return ret;
}
};
int main()
{
test_class c;
c.is_null();
}
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Rolf Magnus Guest
|
Posted: Fri May 07, 2004 7:19 pm Post subject: Re: Zugriff auf double bewirkt segmentation fault |
|
|
Markus Dehmann wrote:
| Quote: | Invalid read of size 8
at 0x8053AE7: test_class::is_null() const
Es ist die prob Variable, nicht die log0-Variable. Aber warum? Die
Klasse ist komplexer, ich habe hier nur den minimalen Code
wiedergegeben. Selbst wenn prob nicht initialisiert wäre, würde das
doch normalerweise noch keinen segfault auslösen, oder? Unter welchen
Umständen darf man einen double-Wert nicht auslesen?
|
Wenn du z.B. einen Zeiger auf ein Objekt deiner Klasse definierst, aber
ohne ihn auf ein solches Objekt zeigen zu lassen, verwendest, oder wenn
du eine Referenz auf ein lokales Objekt aus einer Funktion zurückgibst
und dann weiterverwendest.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|