> -----Oorspronkelijk bericht-----
> Van: Philippe Vachon [mailto:phili...@cowpig.ca] 
> Verzonden: maandag 27 april 2009 13:10
> Aan: Øyvind Harboe
> CC: Nico Coesel; openocd-development@lists.berlios.de
> Onderwerp: Re: [Openocd-development] [PATCH] Fix build errors 
> in SVN on x86_64
> 
> Hi,
> On Mon, Apr 27, 2009 at 08:58:37AM +0200, Øyvind Harboe wrote:
> > > If the 'long long' is changed into 'unsigned long long', the code 
> > > will always work even in wrap-around situations. Perhaps it is a 
> > > better idea to specify (typedef) a timer type as unsigned 
> long long for this purpose.
> > 
> > I don't understand. Subtraction is identical for signed and 
> unsigned 
> > in two's complement representation(I don't care about CPUs 
> that don't 
> > user two's complement! :-)
> > 
> 
> As a rule, comparisons between a signed and an unsigned value 
> are a bit... risky. When you build with -Werror and compile 
> on x86_64, gcc will complain at you. That's the problem.
> 
> > The wraparound case works with signed and unsigned. I'm no more 
> > worried about the wraparound case than I am for, say 
> > 345623623-235423145. :-)
> 
> Realistically, you're correct. I'd argue that nobody would 
> probably need more than 2^32 ms anyways, so why not just make 
> it a u32 and be done with it. ;-)

Timeval returns the current time which consists of the UTC time and a 
microseconds counter. So you will need to have more than 32 bits for a 
comparison. I still think using unsigned math is cleaner otherwise you'll have 
negative times at some point in the future (after 2038) and I'm not sure what 
will happen since the seconds counter will become less negative (from -(2^31) 
towards -1) but the microseconds counter will continue to count up. The fix for 
the Unix epoch in 2038 will probably be making time_t unsigned if isn't 
defined/working that way already.

> > If we are going to change anything here, then *all* places 
> should be 
> > fixed and we should have the reasoning right in the first place.
> > 
> 
> There are a few things I would recommend changing:
> 
> 1) in types.h u32 is badly defined for non-IA32. unsigned 
> long is 8 bytes on x86_64.

There is a standarized C include which defines types which have a platform 
independend bit width. I think its types.h but I'm not sure.

Nico Coesel

_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to