public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
* [Linux-ia64] gcc warnings on truncations?
@ 2000-08-31 15:22 Ted Logan
  2000-08-31 20:16 ` Jim Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Ted Logan @ 2000-08-31 15:22 UTC (permalink / raw)
  To: linux-ia64

Is there a way to get gcc to warn (or ideally, error) on truncations to
shorter types? ie:

	int len = strlen(blah);

should warn because strlen returns a size_t, which on 64-bit platforms
is 8 bits and ints are 4. This would be a nice sanity check in our
porting effort to make sure there's no possibility of loosing data. I've
poked through the docs and nothing seemed to do it.

Ted Logan
Spatial Technology


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

* Re: [Linux-ia64] gcc warnings on truncations?
  2000-08-31 15:22 [Linux-ia64] gcc warnings on truncations? Ted Logan
@ 2000-08-31 20:16 ` Jim Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Wilson @ 2000-08-31 20:16 UTC (permalink / raw)
  To: linux-ia64

	Is there a way to get gcc to warn (or ideally, error) on truncations to
	shorter types? ie:

No.

The ISO C standard says that all expressions undergo default promotions, and
default promotions require promoting char/short to int.  Thus even a simple
expression like
	   short s;
	   short t;
	   s = s + t;
results in truncation to a shorter type, because the result of s+t is an int
and this result must be truncated to fit in the short destination.  A naive
implementation of this warning would give so many false warnings that it
wouldn't be very useful.  An intelligent implementation could cut down on the
false warnings, but would take much longer to write, and hence it is unlikely
that anyone will bother.

Jim


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

end of thread, other threads:[~2000-08-31 20:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-08-31 15:22 [Linux-ia64] gcc warnings on truncations? Ted Logan
2000-08-31 20:16 ` Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox