public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Burlen Loring <burlen.loring@kitware.com>
To: James Gregory <james.jrg@gmail.com>
Cc: Lionel B <lionelb.nospam@gmail.com>, gcc-help@gcc.gnu.org
Subject: Re: Including <iostream> affects whether or not program freezes?
Date: Wed, 09 Jul 2008 18:08:00 -0000	[thread overview]
Message-ID: <4874EEEA.7030000@kitware.com> (raw)
In-Reply-To: <beb51c260807090922s9dccd09o3371992b03da933@mail.gmail.com>

Hi James,

Including a header can affect the program somewhat.variables for 
instance might be placed in a different physical location due to 
slightly different executable size or optimization packing/aligning. 
This is the type of thing that you can see with using uninitialized 
variables. Also if you are running off the end of an array that was 
allocated on the stack(valgrind doesn't catch this as far as I know), 
you can see changes in behavior that come about with variations in the 
compile, because optimization sometimes packs and aligns data so that it 
ends up in a different spot relative to unoptimized build. With 
different memory used different bytes get trashed and hence the run time 
variability. Its often repeatable due to the fact that once the program 
runs it's likely to get loaded into the same physical memory each time 
it runs.

Burlen

James Gregory wrote:
> On Wed, Jul 9, 2008 at 12:28 PM, Lionel B <lionelb.nospam@gmail.com> wrote:
>   
>> On Wed, 09 Jul 2008 03:31:35 +0100, James Gregory wrote:
>>
>>     
>>> 1. Compile with MSVC 7.1, no optimization: my program doesn't freeze 2.
>>> Compile with MSVC 7.1, with optimization: my program doesn't freeze 3.
>>> Compile with gcc 4.2.3 (Ubuntu 64 bit), no optimization: my program
>>> doesn't freeze
>>> 4. Compile with gcc 4.2.3 (Ubuntu 64 bit), with optimization: my program
>>> freezes in a particular function 5. Compile with gcc 4.2.3 (Ubuntu 64
>>> bit), with optimization, and include <iostream> at the top of the file
>>> where the function which freezes is defined: my program doesn't freeze
>>>       
>> You give *way* too little information to even begin to guess what the
>> problem might be... but this smells like a classic case of Undefined
>> Behaviour - sometimes it appears to work, sometimes it doesn't. I.e. you
>> have a bug in your program.
>>     
>
> Sure, I agree it is 99.999999% certain I am doing something wrong
> hence the undefined behaviour. But doesn't it seem somewhat out of the
> ordinary that the behaviour can be affected by which standard library
> header files I include? How can this make a difference to the code
> that gcc produces? It seems unlikely that it's a total coincidence
> that whenever I run the version with iostream included it doesn't
> freeze and whenever I run the version without it does (I just tried
> recompiling the two versions again and the pattern holds).
>
>   
>>> Debugging this is difficult.
>>>       
>> It frequently is ;-) but what other choice do you have? There are tools
>> to help (debuggers such as gdb, memory leak checkers such as
>> valgrind, ...)
>>     
>
> I have used gdb to see which function it freezes in, but as noted I
> cannot compile with full debugging symbols and watch variables/step
> through the code as this removes the bug. valgrind doesn't report any
> problems at all (except a few warnings about functions called in
> external libraries at start up). The reason I originally wanted to
> include iostream was an effort to output the value of variables at
> various points in the function which freezes, but as noted this also
> removes the bug.
>
>   
>> First I would try stripping your program down to a minimal core that
>> exhibits the buggy behaviour. Often in doing so you will isolate and
>> identify the bug. If not seek help here or in a C (or C++, you don't say
>> which language your program is in) forum. You can post minimal code
>> demonstrating the problem.
>>     
>
> But if even including a certain header file can affect the behaviour,
> how can I strip down the program except through random trial and
> error? I guess what I'm trying to say is not "What is wrong with my
> program?", when clearly I haven't given enough information for anyone
> to help, but rather "Does anyone know what sort of thing might be
> affected in the code gcc produces if I include iostream is included?".
>
> (And it is C++ not C, hence <iostream>)
>
> James
>   


-- 
Burlen Loring
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x137

  reply	other threads:[~2008-07-09 17:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-09  3:26 James Gregory
2008-07-09 12:03 ` Lionel B
2008-07-09 16:49   ` James Gregory
2008-07-09 18:08     ` Burlen Loring [this message]
2008-07-09 13:43 ` Andrew Bell
2008-07-09 14:35   ` Andrew Haley
2008-07-09 17:02 ` Chris Jefferson
2008-07-10 10:58   ` James Gregory
2008-08-05  6:45     ` Christoph Bartoschek
2008-08-05  9:31       ` James Gregory
2008-07-12 21:16   ` James Gregory
2008-07-12 21:05     ` James Gregory
2008-07-12 22:11     ` James Gregory

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4874EEEA.7030000@kitware.com \
    --to=burlen.loring@kitware.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=james.jrg@gmail.com \
    --cc=lionelb.nospam@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).