LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-13-2010, 07:32 AM   #1
thesource2
LQ Newbie
 
Registered: Jun 2006
Posts: 9

Rep: Reputation: 0
Question g++: strange compiler warning


g++ compiler (4.4.3-4) gives me a strange warning on the following code:
T & GetElem(int64 i)
{
if((i<0ll)||(i>=m_iSize))
return m_cDummy;
return m_pData[i];
}
Where T - template argument (it's a simple template dynamic array). m_iSize is int64 (long long). m_cDummy is T, m_pData is T*

The warning is: warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false

Does any one know why I get this?
 
Old 04-13-2010, 10:55 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Looks like gcc has optimised out your if statement (assuming that's where the warning came from), and is warning you that the optimised code may not be correct if the values overflow.

See:
http://patrakov.blogspot.com/2008_10_01_archive.html

Dave
 
Old 04-14-2010, 04:49 AM   #3
thesource2
LQ Newbie
 
Registered: Jun 2006
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks for reply. The only question is why gcc optimizes my 'if' if I use -O0 option.
 
Old 04-14-2010, 05:17 AM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hmmm. I'm not particularly familiar with the details of how gcc operates internally - maybe it's not an optimisation, but just how the if comparisons are converted to machine code?

Dave
 
  


Reply

Tags
c++, programming



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
Suppress a particular gcc compiler warning? lamar_air Programming 7 10-09-2011 02:04 AM
C++: compiler error or warning unihiekka Programming 12 12-03-2008 11:18 AM
Compiler warning on HP-UX 11.23 Itanium patilvidya Programming 2 04-30-2007 01:22 AM
compiler warning! kalleanka Programming 3 07-13-2006 05:42 AM
Strange warning Gins Linux - General 2 04-17-2006 02:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:39 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