[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: allocate 2d pointer. is ths a bug ?

From: Bernd Strieder
Subject: Re: allocate 2d pointer. is ths a bug ?
Date: Thu, 10 Aug 2006 14:54:52 +0200
User-agent: KNode/0.10.1

h wrote:

> Thanks Mehturt.
> but, it works through g++ on Cygwin and GNU/Linux machine without
> MS-VC++ 6.0 on win32 machine.
> i know i've attached code are has a problem.
> okay, i wanna know exactly attached code are why looks working good in
> g++ only.
> that's it.

I cannot reproduce the exact behaviour. The app crashes at different
places depending on optimization.

If you compile with optimization and warnings turned on, then g++ will
tell you something (g++ -O2 -Wall ...). If you want to know exactly
what happens, you have to use a debugger to look what the values are
initialized to. Or you have to insert some more output. But don't be
surprised, if behaviour changes completely, when you do so. This is the
very nature of undefined behaviour, it can be like a phantom. You have
done a simple bug and it will bug you for weeks, randomly. This is why
it is so nice that the compiler can warn you about missing

I think it is prossible to create both kinds of apps with undefined
behaviour on all platforms, non-crashing and crashing ones. The
differences are subtle, and you have to dig deeply into the whole
runtime system to understand. You need about the expertise a hacker
uses to break into some application.

There is no point in looking for the exact cause, that undefined
behaviour does not result in a crash, just remove the bug and be happy,
and remember next time you declare a pointer to initialize, and
remember to turn warnings on next time you compile.

Bernd Strieder

reply via email to

[Prev in Thread] Current Thread [Next in Thread]