On Wed, Jan 25, 2017 at 01:21:36PM +0000, Joseph Manning wrote:
> Dear All,
>
> Have you ever wondered how the Lua Team manage to retain their
> ever-youthful good looks?
> ....
> So, I was timing a section of code by wrapping it in calls to
> 'os.clock( )', and under certain conditions, the second such call
> returned a value that was substantially smaller than the first --
> in fact, it returned a negative value, which should never happen.
....
In C I just explicitly type cast clock_t values (each operand individually)
to unsigned long, and everything just magically works because of modulo
arithmetic. But I'm making assumptions about the platform--that it's two's
complement and that unsigned long is the corresponding unsigned type for
clock_t. I really only use it for debugging and quick benchmarking. But as
mentioned in that ticket there's no [easy] portable way to figure out which
unsigned type to convert to. For Lua you'd probably have to use a function
with conditional logic, just like a portable C solution would likely use.
....
-- Ross Berteig Ross@CheshireEng.com Cheshire Engineering Corp. http://www.CheshireEng.com/ +1 626 303 1602