[ENet-discuss] time.h

Stefan Ludewig stefan.ludewig at exitgames.com
Thu Jul 22 10:42:42 PDT 2010


I do not see any way, an overflow would make any problems for subtracting
two signed int, the result is still correct, but an overflow does indeed
lead to problems. Actually the double amount for positive values of an
unsigned is only relevant for absolute times, not differences between two
times, as all differences greater than 24 hours are treated as an overflow
by time.h macros anyway, so I think, you could simply interpret the bytes as
unsigned int, if passing it to a 3rd party time library, but interpreting it
as signed, when comparing timestamps. The absolute value of a single
timestamp without comparing it to a second one would rarely be of any use,
as even unsigned int overflows every 1,5 months.



*Von:* enet-discuss-bounces at cubik.org [mailto:enet-discuss-bounces at cubik.org]
*Im Auftrag von *Nuno Silva
*Gesendet:* Donnerstag, 22. Juli 2010 17:10
*An:* Discussion of the ENet library
*Betreff:* Re: [ENet-discuss] time.h



Sorry for double-messaging, but i need to rephrase what i said: unsigned int
has twice as many possible values than signed int and a signed int would
cause overflows more often than unsigned int.

On Thu, Jul 22, 2010 at 4:09 PM, Nuno Silva <little.coding.fox at gmail.com>
wrote:

Problem is that unsigned int has more storage for positive values than
signed int (by about half), not to mention all time libraries and
specifications go with unsigned values too.

On Thu, Jul 22, 2010 at 4:02 PM, Stefan Ludewig <
stefan.ludewig at exitgames.com> wrote:

  Hi all.



What is the reason enet uses unsigned int and these time overflow macros in
time.h?

I enet would simply use signed int, these macros would not be needed at all.

For example if we have a time INT_MAX and a second one INT_MIN , 1ms later,
directly after the overflow, INT_MIN-INT_MAX would result in the correct
difference 1 and INT_MAX-INT_MIN in the correct difference -1. No need for
the use of ENET_TIME_DIFFERENCE at all for signed int.

On the other hand, if we call ENET_TIME_DIFFERENCE(a, b) with a==1 and b==2,
the result is b-a -> 1, although the correct result would have been -1.

If some functions need unsigned times or return unsigned times, you could
simply them from/to signed int, and all would be fine.

So I do not see any advantage in using unsigned int and time.h macros
instead of simply use signed int. Can you tell me the reasons for the
unsigned + time.h solution?



Thx,

Stefan.





_______________________________________________
ENet-discuss mailing list
ENet-discuss at cubik.org
http://lists.cubik.org/mailman/listinfo/enet-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20100722/3d933c7c/attachment-0001.html>


More information about the ENet-discuss mailing list