Pergunta

In POSIX 2008 part of clock function definition:

The value returned by clock( ) may wrap around on some implementations.

also

CLOCKS_PER_SEC is defined to be one million in <time.h>.

In C standard clock function has important note:

In order to measure the time spent in a program, the clock function should be called at the start of the program and its return value subtracted from the value returned by subsequent calls.

also

CLOCKS_PER_SEC: which expands to an expression with type clock_t (described below) that is the number per second of the value returned by the clock function.

In POSIX they say that the information in POSIX standard is aligned with c standard however in c standard CLOCKS_PER_SEC is implementation-defined unlike with POSIX which have a value, In c standard no wrapping should occur - got that from the example used to calculate application running time - but in POSIX they said that wrapping will happened every 36 minutes.

When i use c compiler - such as Gcc, Clang or even I.C.L. - in Linux, is clock return value will wrap or not known that POSIX and c standard use same header time.h?

note: instead of Linux any platform may used, i used it here to give example.

Thanks

Foi útil?

Solução

This is a bug in POSIX. It's been reported, resolved, and will be fixed in the next version. See: http://austingroupbugs.net/view.php?id=686

I suspect it will take a good deal longer to get all the buggy implementations fixed.

Outras dicas

The POSIX requirements are aligned with, but stricter than those in the C standard.

The C standard requires that CLOCKS_PER_SEC be defined by the compiler. POSIX does the same, but says it must have one specific value.

The C standard doesn't really say anything about wraparound -- there's no direct statement that it can wrap around, but also no prohibition saying it can't. Given a finite size, it's inevitable that it'll wrap around eventually though.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top