help-gplusplus
[Top][All Lists]
Advanced

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

Re: Crash following optimisation goes away when inserting printf


From: Ulrich Eckhardt
Subject: Re: Crash following optimisation goes away when inserting printf
Date: Tue, 23 Jan 2007 22:46:52 +0100
User-agent: KNode/0.10.4

Martin Franke wrote:
> The crash occurs in
> the initialisation routine of a certain module. Now, when inserting a
> printf("bla") right at start-up in main() the crash goes away, removing
> it makes it re-appear, so it is perfectly reproducible. The printf is in
> a different object file than where the crash happens and quite a lot of
> code is executed between the printf and the crash.
> 
> So my questions are:
> - Is this a side-effect to be expected?

Yes, in that it can change the behaviour, no in that printf() is not a cure
to make crashes go away. ;)

> - How can the additional printf in one object file can have a
> side-effect on the code in another object file?

Every function call modifies the stack and possibly some registers (I'm not
100% sure when and how the latter are modified). The former means that if
you then create an uninitialised variable on the stack its value might be
modified. The latter means that code to save and restore register content
is created. Both together or each for itself could cause the program's
behaviour to change, in particular if there is some undefined behaviour
already going on.

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/



reply via email to

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