tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: foo = (unsigned)bar; (was Re: dhcpcd-4.0.0-alpha1 ready for review)

On Fri, 18 Apr 2008, Roy Marples wrote:
> OK, this piqued my curiosity last night. What would this be expected to do
> signed char bar;
> unsigned char foo;
> foo = (unsigned)bar;

(unsigned) always means the same as (unsigned int), regardless of the
type of the thing on the right hand side.  Similarly,

        unsigned foo;

means the same as

        unsigned int foo;

> I can't find any documentation on this, so does anyone have any
> opinion that can hopefully be backed up with reference documentation?

A web search for "WG14 N1124 pdf" should find the latest committee draft
from shortly before the C99 standard was finalised.  Then see section
6.7.2, paragraph 2 read in conjunction with paragraph 5, which makes it
clear that "unsigned" and "unsigned int" mean the same thing in a type
specifier.  I'd have to do more work to prove that the same applies to
the thing inside the parentheses of a cast (which is a "type-name", not
a "type specifier").

--apb (Alan Barrett)

Home | Main Index | Thread Index | Old Index