This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Wrong warning? ISO C restric ts enumerator values to range of âintâ

On 2008-02-06 21:17:53 +0100, Manuel López-Ibáñez wrote:
> On 06/02/2008, Vincent Lefevre <> wrote:
> > The problem is the cast (suggested by Dave Korn), not the enum itself:
> > (int) 0x80001000
> >
> What is the problem with the cast? Do you want a warning for the
> conversion that you asked for with the cast? We want about implicit
> conversions with -Wconversion but if you use a cast, we understand
> that you really mean to perform the conversion.

The problem is that the conversion here is implementation-defined,
and may raise a signal on some platforms; so, this is a non-portable
construct. I think that a warning should be issued because the value
is out-of-range. This would allow to detect problems that can arise
on some platforms, e.g. with code like:

#include <stdio.h>
#include <limits.h>

int main (void)
  printf ("%ld\n", (long) UINT_MAX);
  return 0;

On platforms where int and long have the same size (so that UINT_MAX
isn't representable in a long), a warning would be useful.

Vincent Lefèvre <> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]