Jump to content
pan

Timer sys_tick

Recommended Posts

Hello, I was coding some modifications and I found out that sys_tick() is declared as int64 and I think it should've been declared as unsigned int64.

In windows this function calls pGetTickCount64(), from winapi, which is declared as ULONGLONG that is equivalent to unsigned int64.

@srccommontimer.c static int64 sys_tick(void)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724411(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/cc230393.aspx

Edited by pan

Share this post


Link to post
Share on other sites

There were reasons why signed was chosen instead of unsigned. Most operations we do with tick are tick differences, and that kind of operation with unsigned variables requires extra care that's not required with signed ones. There really isn't any benefit in using unsigned in most cases (especially if it's just to say that the variable should never be negative), and I strongly believe the only place where one should use unsigned is where the value isn't used as a plain number, but a bit field or similar. If the point about using unsigned is to allow larger values, well, the int64 overflow will happen about 292 million years from now. I believe that, whichever intelligent life forms will be alive by then, if any, will be able to use a different 'zero', or a larger variable.

 

This article on the topic is an interesting read: http://www.soundsoftware.ac.uk/c-pitfall-unsigned

Share this post


Link to post
Share on other sites

Thank you for recommending the article, it's very good indeed. Sorry for any inconvenience :x

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.