public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Warning flags for unsigned operations (unsafe)
@ 2004-09-22 15:38 Thomas R. Truscott
  2004-09-22 16:18 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Thomas R. Truscott @ 2004-09-22 15:38 UTC (permalink / raw)
  To: gcc

 > I couldn't find out if gcc had a 
 > warning flag for unsigned operation. For example, even the linear 
 > interpolation on [a,b] can be tricky to code:
 > 
 >  c = a + t * (b - a);  //unsafe

Not for this situation.  I think a warning would be appropriate
when an unsigned quantity involving subtraction
is widened or converted to double.

 >   Your code has a design flaw and is not valid.  

Uh, that misses the whole point of warning messages, doesn't it?

Tom Truscott

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Warning flags for unsigned operations (unsafe)
@ 2004-09-22  5:33 Mathieu Malaterre
  2004-09-22 14:57 ` Dave Korn
  2004-09-24  6:20 ` Giovanni Bajo
  0 siblings, 2 replies; 11+ messages in thread
From: Mathieu Malaterre @ 2004-09-22  5:33 UTC (permalink / raw)
  To: gcc

Hello,

	I have been googling around and I couldn't find out if gcc had a 
warning flag for unsigned operation. For example, even the linear 
interpolation on [a,b] can be tricky to code:

1.
c = a + t * (b - a);  //unsafe

2.
c = (1.0 - t) * a + t * b; //safe

Number 1 will fail when both a and b are unsigned and let say b - a = -1 
(math speaking). Is there something in gcc that could warn me for this 
kind of operation ?

Thanks,
Mathieu

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-09-24  4:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-22 15:38 Warning flags for unsigned operations (unsafe) Thomas R. Truscott
2004-09-22 16:18 ` Robert Dewar
2004-09-22 16:31 ` Robert Dewar
2004-09-22 16:53 ` Dave Korn
  -- strict thread matches above, loose matches on Subject: below --
2004-09-22  5:33 Mathieu Malaterre
2004-09-22 14:57 ` Dave Korn
2004-09-22 15:12   ` Robert Dewar
2004-09-22 20:50   ` Luca Masini
2004-09-23  1:37     ` Mathieu Malaterre
2004-09-24  6:20 ` Giovanni Bajo
2004-09-24  6:31   ` Mathieu Malaterre

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).