Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!haven!uflorida!novavax!proxftl!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Implicit and explicit casts... Message-ID: <105@twwells.uucp> Date: 20 Oct 88 00:38:45 GMT References: <8810111925.AA21750@ucbarpa.Berkeley.EDU> <14028@mimsy.UUCP> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 28 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <14028@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: : short s; : int i; : i = (unsigned char)s; : : which moves the value in `s' through four(!) types before reaching : `int' and storing in `i': : : what type : ---- ---- : s short, lvalue : s int, rvalue : s unsigned char, rvalue : s unsigned int, rvalue I understand that there are some compilers that do not do the truncation properly. In other words, int i = (unsigned char)0xFFFF; stores 0xFFFF in i, instead of 0xFF (assuming 8 bit bytes, of course). Such compilers are broken, but if portability is a concern, one should avoid assuming that casting (or for that matter, assigning to a char) properly truncates a value. --- Bill novavax!proxftl!twwells!bill