Pergunta

What is the maximum value that I can give to the delay() function in C. I am not able to find any documentation. I am using gcc compiler. Is it going to be platform dependent by any chance?

Foi útil?

Solução

Is it going to be platform dependent by any chance?

To begin with, the very function itself is platform dependent, so if you're hoping to be standards compliant or portable, you shouldn't be using it. You say in the comments that you use QNX Neutrino; the QNX documentation for the function indicates the fact that it's QNX-specific by saying "QNX 4" under the "Classification" heading.

To actually answer the question, I hardly think there's any reason to assume there's any limitation to the argument other than that of its type. On a platform with 32-bit ints, you should be able to sleep for 2^32-1 milliseconds, or ~49 days. On a platform with 64-bit ints, you should be able to sleep for 2^64-1 milliseconds, or ~585 million years.

However, should you want to use a standards-compliant function instead, I suggest using sleep or usleep instead (depending on what resolution you need), which are specified by POSIX and supported by most non-POSIX systems as well. They should also be guaranteed not to have any limitations on the maximum length of time you're allowed to sleep other than that of the system's length of int.

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