Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Date: Fri, 25 Nov 2016 12:12:27 -0800 Organization: None to speak of Lines: 35 Message-ID: References: <5836fa81$0$4275$426a74cc@news.free.fr> <87wpfsvs8p.fsf@bsb.me.uk> <871sxz7qzw.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="3c5e60c3a5e134696d7a5f0d024ade78"; logging-data="28230"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+J7A+ZeLpJC350QkXQaWFB" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:M821pS8QuRHgzQnpIJA9a7LhanM= sha1:dc4D26ubF4WKsK+pjIH83oBwDpY= Xref: csiph.com comp.lang.c:97475 supercat@casperkitty.com writes: > On Friday, November 25, 2016 at 5:12:34 AM UTC-6, Ben Bacarisse wrote: >> It's not 100% clear if this is supposed to apply to unsigned int when >> int has the same positive range. I'm not sure but I lean towards not. >> Why mention unsigned int if the objects in question were not supposed to >> exclude them? Implementations where unsigned promotes to int would be >> pathological in some senses. > > Implementations where every unsigned value is representable as "int" are > hardly pathological. I won't argue the meaning of the word "pathological", but such implementations are certainly rare. > That would actually be a common state of affairs in > sign-magnitude or ones'-complement implementations. I've never used a sign-and-magnitude or ones'-complement implementation, but I'd expect such an implementation to use all the bits of a word for both signed and unsigned types. For example, if int and unsigned int are, say, 16 bits wide, I'd expect that most likely int would have a range of -32767..+32767, and unsigned int to have a range of 0..65535. Certainly there are other possibilities, including ones where the range of unsigned int matches the non-negative subrange of int, but I'd expect that to be unusual, perhaps even nonexistent. Do you have a concrete example, or are you just speculating? [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"