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-25 22:54 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87shqf5fwd.fsf@bsb.me.uk> (permalink) |
| References | (2 earlier) <o18tj3$d04$1@dont-email.me> <o192rl$tok$1@dont-email.me> <871sxz7qzw.fsf@bsb.me.uk> <e6af8d35-de73-4893-ace7-eb617a805475@googlegroups.com> <lnfumfb9p0.fsf@kst-u.example.com> |
Keith Thompson <kst-u@mib.org> writes:
> 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.
It was not a good word! I'm not sure I meant anything other that "very
unusual".
>> 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?
Unisys systems are a good source because they have C compilers and odd
hardware. I've found an example of both from that stable. One[1] has
40-bit words where unsigned int has a padding bit and thus a range
exactly equal to that of signed int. (unsigned short and unsigned long
are also the same size for good measure.) A wrinkle is that I don't
think this is a C99 compiler and the wording is different in C90.
The other[2] has 36-bit words and unsigned int uses all of them to give
the situation you describe. This is, I think, a C99 compiler.
Do you have a view on whether the text in question is intended to
include unsigned being promoted to int? Here it is in full:
The following may be used in an expression wherever an int or unsigned
int may be used:
-- An object or expression with an integer type whose integer
conversion rank is less than or equal to the rank of int and
unsigned int.
-- A bit-field of type _Bool, int, signed int, or unsigned int.
If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned
int. These are called the integer promotions.
I've always read the last paragraph more or less on it's own, but taken
together with the preceding text it seems at least possible that objects
or expressions of type unsigned int are not to be considered for
promotion, because the text is about those object of expression that can
be used instead of an int or unsigned int.
Maybe this is been resolved in a DR, but I could not find one in an
admittedly rather cursory search.
[1] MCP/AS, C Programming Reference Manual Volume 1: Basic
Implementation, MCP 12.0, April 2008.
[2] Application Development Solutions, C Compiler Programming Reference
Manual Volume 1: C Language and Library, Level 10R4, February 2013.
--
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