Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #6811
| From | "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Slow -- VERY slow brain |
| Date | 2011-06-16 18:51 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <itdboa$kv4$1@dont-email.me> (permalink) |
| References | <itbdgg$aer$1@dont-email.me> <60b67c1e-da5f-48d5-8e5b-f99a34154b4c@r33g2000prh.googlegroups.com> <61cb1940-6462-4539-965f-0d08de716c0b@r35g2000prj.googlegroups.com> |
* madamemandm@yahoo.com, on 16.06.2011 16:31:
> On Jun 16, 9:22 am, "madamema...@yahoo.com"<madamema...@yahoo.com>
> wrote:
>> On Jun 15, 6:08 pm, "Alf P. Steinbach /Usenet"<alf.p.steinbach
>>
>>
>>
>> +use...@gmail.com> wrote:
>>> Well, I think, it's not just me.
>>
>>> Since it's in the FAQ, and since we have discussed this for years, it must be
>>> nearly all of us: we're idiots.
>>
>>> I'm thinking of the argument for `unsigned` type, that you can do
>>
>>> void foo( unsigned n )
>>> {
>>> assert( n< maxN );
>>> // blah
>>> }
>>
>>> which is reportedly both more concise and more efficient than
>>
>>> void foo( int n )
>>> {
>>> assert( 0<= n&& n< maxN );
>>> // blah
>>> }
>>
>>> But, the second one can always be written as
>>
>>> void foo( int n )
>>> {
>>> assert( unsigned( n )< maxN );
>>> // blah
>>> }
>>
>> [snip]
>> Really? On a system where UINT_MAX = INT_MAX = -INT_MIN wouldn't the
>> second fire the assert while the third would not? (Assuming maxN>
>> 0).
>>
>> (Not that the effeciency argument isn't bogus anyway, but I don't
>> think this demonstrates it.)
>
> Oops! Should double check before I send. Let n = INT_MIN and assume
> maxN> 1.
The standard guarantees that when x is of integral type then unsigned(x) is
congruent to x modulo 2^n where n is the number of value representation bits in
`unsigned`. No, this isn't it a quote. I just haven't had my coffee yet so not
quite able to express things more simply, sorry.
Anyway, you don't need the math to see that the two codes do the same.
In the first case the conversion happens at the call site as an implicit
promotion, in the second case the same conversion happens locally via a cast.
Cheers & hth.,
- Alf
--
blog at <url: http://alfps.wordpress.com>
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-16 01:08 +0200
Re: Slow -- VERY slow brain "Balog Pal" <pasa@lib.hu> - 2011-06-16 01:44 +0200
Re: Slow -- VERY slow brain Puppet_Sock <puppet_sock@hotmail.com> - 2011-06-16 06:25 -0700
Re: Slow -- VERY slow brain Noah Roberts <dont@email.me> - 2011-06-29 10:05 -0700
Re: Slow -- VERY slow brain Keith H Duggar <duggar@alum.mit.edu> - 2011-06-16 07:00 -0700
Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-16 07:22 -0700
Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-16 07:31 -0700
Re: Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-16 18:51 +0200
Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-16 13:10 -0700
Re: Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-16 22:46 +0200
Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-17 07:38 -0700
Re: Slow -- VERY slow brain Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-06-17 18:06 +0200
Re: Slow -- VERY slow brain "madamemandm@yahoo.com" <madamemandm@yahoo.com> - 2011-06-17 10:49 -0700
Re: Slow -- VERY slow brain "Paul" <pchristor@yahoo.co.uk> - 2011-06-17 18:27 +0100
Re: Slow -- VERY slow brain Werner <werasm@gmail.com> - 2011-06-17 01:33 -0700
Re: Slow -- VERY slow brain Öö Tiib <ootiib@hot.ee> - 2011-06-17 07:48 -0700
Re: Slow -- VERY slow brain Werner <werasm@gmail.com> - 2011-06-17 09:39 -0700
Re: Slow -- VERY slow brain "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-17 19:59 +0200
csiph-web