.rhavin grobert
10/21/2008 7:23:00 PM
On 21 Okt., 20:23, blargg....@gishpuppy.com (blargg) wrote:
> In article <gdl4cv$28...@aioe.org>, Zeppe
>
>
>
> <ze...@remove.all.this.long.comment.yahoo.it> wrote:
> > Maxim Yegorushkin wrote:
> > >>> ________________________________________________
> > >>> unsigned int iTest; // lets asume 'int' = 32bit
> > >>> iTest = 0xFFFFFFFF;
> > >>> iTest++;
> > >>> ________________________________________________
> > >>> does the std say something what shall happen now?
> > >>> May i safely assume iTest is now 0 or is it CPU or sys-dependent?
> > >>> TIA, ~.rhavin;)
> > >> the second one.
>
> > > Wrong answer.
>
> > > The C and C++ standards guarantee the wrapping for unsigned integer
> > > types.
>
> > My bad. Actually, I know that piece, I just ignored the comment as a
> > compiler would do. So, the result IS sys-dependent, BUT if you assume
> > that all the systems in which that code will be compiled are going to be
> > 32bit, then is safe to assume that iTest is going to be zero after the
> > increment.
>
> How about this:
>
> unsigned i = UINT_MAX;
> i++;
> assert( i == 0 );
Actually it's that one:
________________________________
typedef unsigned __int64 QUAD;
class foo {
foo(): m_qSel(0) {};
public:
inline QUAD NextSelector() {return m_qSel++;};
private:
QUAD m_qSel;
};