Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!elsie!ado From: ado@elsie.UUCP (Arthur David Olson) Newsgroups: comp.lang.c Subject: Re: unsigned short vs. negative constant Message-ID: <7404@elsie.UUCP> Date: Sun, 3-May-87 17:12:21 EDT Article-I.D.: elsie.7404 Posted: Sun May 3 17:12:21 1987 Date-Received: Tue, 5-May-87 01:18:08 EDT Followup-To: poster Organization: NIH-LEC, Bethesda, MD Lines: 34 Thanks to everyone who replied to replied to my question about what the code #include "stdio.h" main() { unsigned short us; us = ~0; (void) printf("%d\n", us == -1); } should print on systems where sizeof short < sizeof int, and what it actually does print on various systems. The scoop: * Some systems simply print 1, including Elsie herself (a VAX 11-750 running MORE/bsd 4.3), a VAX 11-780 running 4.3 BRL UNIX, and an Ultrix 1.2 system. * Other systems systems simply print 0, including KCC on TOPS-20, an AT&T 3B5 running System V Release 2.0.1 3B5 Version 2, an a "moto '030 machine running System V.2." * The latest Sun systems print 1; issuing a warning during compilation. * A Concurrent system prints 0; it issues a warning during compilation. Sun systems may do this in the future. Saber-C prints 0; it issues a warning. * K&R can't be used to resolve the issue, since it predates unsigned shorts. * The consensus of opinion is that under X3J11's "value-preserving" widening rules, the program should print 0. The moral of the story: folks who maintain the various versions of lint may want to have it look for and warn about such code, at least when lint is run in "check portability" mode. -- UUCP: ..seismo!elsie!ado ARPA: elsie!ado@seismo.CSS.GOV Elsie and Ado are trademarks of Borden, Inc. and Ampex.