Re: What does a sleep(-1) do?

Barry Margolin <barmar@xxxxxxxxxxxx> writes:
In article <44b37343$0$31648$e4fe514c@xxxxxxxxxxxxxx>,
Casper H.S. Dik <Casper.Dik@xxxxxxx> wrote:
Barry Margolin <barmar@xxxxxxxxxxxx> writes:
In article <44b219f9$0$31637$e4fe514c@xxxxxxxxxxxxxx>,
Casper H.S. Dik <Casper.Dik@xxxxxxx> wrote:
jeroendecock@xxxxxxxxx writes:
Can someone explain what the sleep function with a negative value does?
You can't call sleep with a negative argument:

unsigned int sleep(unsigned int seconds);

If you pass it "-1" the implementation will most likely see this
as the highest possible unsigned number.

"most likely"? As long as the proper header file has been used so that
the prototype has been seen, it's REQUIRED to treat it this way (as all
the previous responses pointed out).

Oh, is a two's complement implementation a requirement for POSIX

Not POSIX, C. C says that when a negative number is assigned to an
unsigned int, it's converted modulo UINT_MAX+1.

Right. On a two's complement implementation, the conversion can be
done just by copying the representation. On a ones' complement or
sign and magnitude implementation, the compiler will have to do a
little extra work do to the conversion correctly.

(The C99 standard requires one of those three representations for
signed integer types; the C90 standard is less specific, but has the
same requirements for conversions.)

Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <>
San Diego Supercomputer Center <*> <>
We must do something. This is something. Therefore, we must do this.