Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? |
| Date | 2016-11-29 12:01 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <8737iah4uv.fsf@bsb.me.uk> (permalink) |
| References | (4 earlier) <871sxz7qzw.fsf@bsb.me.uk> <e6af8d35-de73-4893-ace7-eb617a805475@googlegroups.com> <lnfumfb9p0.fsf@kst-u.example.com> <c808ca65-c717-4c0f-96c2-2e84911e5195@googlegroups.com> <ln4m2qag9n.fsf@kst-u.example.com> |
Keith Thompson <kst-u@mib.org> writes: > supercat@casperkitty.com writes: >> On Friday, November 25, 2016 at 2:11:17 PM UTC-6, Keith Thompson wrote: >>> supercat writes: >>> > 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. >> >> I certainly won't dispute that. >> >>> > 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? >> >> http://public.support.unisys.com/2200/docs/cp14.0/pdf/78310422-011.pdf > > Thank you for posting that. > >> I don't know exactly how such hardware works, but I would expect that since >> the compiler achieves conformance by looping off a bit, that would imply that >> having an unsigned type support all 36 bits would be difficult. > > (The link is to a download page, not to the actual PDF.) > > I think you've misread it. > > (Not relevant to the point, but section 4.3 treats "plain integers" and > "signed integers" as distinct, which is nonsense.) > > For example, int and unsigned int are both 36 bits. The range of int is > shown as -2**35+1 to +2**35-1, and range of unsigned int as 0 to > 2**36-2. (There's a conformance option that makes the upper bound of > unsigned int 2**36-1.) There is another Unisys C implementation that is an example of the problem. It has 40 bits types and int can store all the values of unsigned int. In effect there is a padding bit in the unsigned types (except for unsigned char). I suspect this is because it uses floating point hardware to do all arithmetic, but that's just a guess. https://public.support.unisys.com/aseries/docs/clearpath-mcp-16.0/pdf/86002268-205.pdf -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Francois Grieu <fgrieu@free.fr> - 2016-11-24 15:33 +0100
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-24 14:59 +0000
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Francois Grieu <fgrieu@free.fr> - 2016-11-24 18:34 +0100
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? supercat@casperkitty.com - 2016-11-24 14:03 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? David Brown <david.brown@hesbynett.no> - 2016-11-25 09:50 +0100
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Noob <root@127.0.0.1> - 2016-11-25 09:44 +0100
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? David Brown <david.brown@hesbynett.no> - 2016-11-25 11:14 +0100
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-25 11:12 +0000
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? supercat@casperkitty.com - 2016-11-25 10:50 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Keith Thompson <kst-u@mib.org> - 2016-11-25 12:12 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Nick Bowler <nbowler@draconx.ca> - 2016-11-25 21:45 +0000
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? supercat@casperkitty.com - 2016-11-25 13:58 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Keith Thompson <kst-u@mib.org> - 2016-11-28 23:37 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-29 12:01 +0000
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? supercat@casperkitty.com - 2016-11-29 07:39 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Keith Thompson <kst-u@mib.org> - 2016-11-29 09:12 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-25 22:54 +0000
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Nick Bowler <nbowler@draconx.ca> - 2016-11-25 22:01 +0000
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-11-25 23:22 +0000
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-10 07:22 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-01 10:16 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Barry Schwarz <schwarzb@dqel.com> - 2016-12-01 11:06 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? supercat@casperkitty.com - 2016-12-01 12:40 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? David Brown <david.brown@hesbynett.no> - 2016-12-02 09:28 +0100
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? Tim Rentsch <txr@alumni.caltech.edu> - 2016-12-10 07:13 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? supercat@casperkitty.com - 2016-12-10 10:41 -0800
Re: Is uint32_t foo(uint32_t x) { return (uint32_t)(x*x); } portable? supercat@casperkitty.com - 2016-11-24 07:40 -0800
csiph-web