unsigned sizeof()

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Feb 15 04:37:39 AEST 1990


In article <6042 at arctic.nprdc.arpa> stanonik at nprdc.navy.mil (Ron Stanonik) writes:
>Yes, 2nd edition K&R says the result of sizeof is unsigned (though
>it also says the type is implementation-defined, p204, which I find
>contradictory).  Why though?  Why make sizeof unsigned?

sizeof was changed to produce an unsigned int somewhere around 1980.
The main reason was that a signed int was simply unable to express the
size of some C data objects encountered in split-I&D PDP-11 applications.
It is also logically unsigned anyway.

>Sorry if this is old news.  It was a surprise to us; ie, sizeof
>on our suns and vax (4bsd) returns signed.

Well, their C compilers were based on old, decrepit versions of PCC.
And non-portable programs abound, so you really shouldn't be surprised
that you encountered one.



More information about the Comp.unix.wizards mailing list