LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2009, 04:41 PM   #1
halfpower
Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 241

Rep: Reputation: 31
Compiler Bugs in G++ 4.3.3? Strange behavior at run time


I installed Slackware 10.1 or 10.2 (32 bit)two or three years ago. I've recently installed Ubuntu 9.04 (64 bit). I had some small programmes that I had written in C/C++. They compiled and ran on Slackware, but now when I compile them on Ubuntu, I get a segmentation fault when I try to run them. Actually the compiled programs seem to be behaving unpredictably, as declarations of unused variables is resulting in different output values. The only explanation for this is that there is a bug in G++ 4.3.3. Does anyone know anything about this and what my problem might be. Superficially, it appears to be a fairly big bug.
 
Old 10-31-2009, 04:54 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
I would doubt there is a bug in the compiler, unless the version your using is new and possibly unstable, or at least not as stable as previous, more thoroughly tested, versions.

Could you post your code? Try and minimize it as much as possible, while still being able to reproduce the problem. Basically, narrow the bug down to say 25 lines of code or fewer.

EDIT: Compile with flags "-Wall -pedantic", on both OSs, and compare the (compiler) output. Are they equivalent?

Last edited by nadroj; 10-31-2009 at 05:06 PM.
 
Old 10-31-2009, 06:30 PM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by halfpower View Post
I installed Slackware 10.1 or 10.2 (32 bit)two or three years ago. I've recently installed Ubuntu 9.04 (64 bit).
Should I assume you have also switched the programs you are compiling from 32 bit to 64 bit?

Quote:
the compiled programs seem to be behaving unpredictably, as declarations of unused variables is resulting in different output values.
The declarations of unused variables probably affects the allocation sequence of used variables.

So you probably have some data clobber whose effect depends on the exact placement of the program's data. Many such data clobbers are likely from recompiling in 64 bit mode a program that made assumptions about pointers and/or size_t that only work in 32 bit.

If you install the right additional packages (32 bit libraries) in Ubuntu, you should be able to get your program compiled and built with -m32 on the 64 bit system. That may help diagnose whether the cause is an error in your program revealed by the switch to 64 bit as opposed to an error in your program revealed by the switch to a newer version of GCC.

If you were skilled at debugging, you could find the problem more directly by using gdb to examine the nature of the seg fault. But if you knew how to do that, I think you wouldn't have posted what you did.

Quote:
The only explanation for this is that there is a bug in G++ 4.3.3.
That is nonsense.

Bugs in programs often have no symptoms. You may change something, such as the version of GCC, and your symptom free bug may suddenly have severe symptoms.

The fact that your program had no symptoms in an earlier version of GCC does not mean your program didn't have a bug that causes the present symptom.

If you changed from 32 bit to 64 bit, that is more likely to be what revealed the "bug". But any change can reveal a bug.
 
Old 10-31-2009, 06:48 PM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
make sure you compile with -Wall and see if there is any warnings that were not in there last time.
 
Old 11-01-2009, 03:58 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by smeezekitty View Post
make sure you compile with -Wall and see if there is any warnings that were not in there last time.

And with -Wextra.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange file behavior nc3b Linux - General 2 08-23-2006 01:27 PM
Very Strange CD-RW Permission Behavior ! sarah_b Linux - Newbie 8 01-06-2006 02:33 PM
Very Strange Behavior raysr Mandriva 4 08-31-2004 02:06 PM
Strange Behavior andrewb758 Linux - Hardware 5 08-31-2003 02:42 PM
strange behavior abhijit Linux - General 3 07-09-2003 11:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration