[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Compilation warnings in Lua 5.2.1 (size_t to unsigned int conversion)
- From: William Ahern <william@...>
- Date: Thu, 27 Sep 2012 12:19:39 -0700
On Thu, Sep 27, 2012 at 12:05:28PM -0700, William Ahern wrote:
> On Thu, Sep 27, 2012 at 01:48:03PM +0100, liam mail wrote:
<snip>
> > You do realise this is an example of a "common warning" as outlined in
> > the C99 Annex? Personally I much prefer a warning to be generated
> > rather than not, even if you override it as you know better than the
> > compiler.
> >
>
> I disagree. The Annex speaks of implicit narrowing of signed integers,
> although the language is loose because it's not part of the standard proper.
> But if you grep the entire standard for "narrow" or "narrowing", it's always
> in the context of signed integrals.
>
> Anyhow, here's an example of an implicit signed narrowing:
>
> char foo[1] = 'a';
>
FWIW, I realize this is a constant expression and not really a narrowing
conversion because the value is representable in char. But imagine code like
int ch = getch();
char *foo = ...
while ((EOF != (ch = getch())))
*foo++ = ch;
And anyhow, the reason why signed integral narrowing conversions are a
common diagnostic is because signed narrowing conversions are implementation
defined. Wouldn't you want to know about behavior that isn't strictly well
defined in C, and which isn't a common idiom?
Unsigned to unsigned conversions are _always_ well defined in C, and are a
very common idiom.
I'll let you have the last word.