Hacker News new | past | comments | ask | show | jobs | submit login

> Unfortunately, the C standard prescribes that failing to call `srand` must be equivalent to calling `srand(1)`, so I don't think glibc can get away with this trick.

I think it could. Just supply two implementations of rand(): a strictly conforming one without this optimisation, and a less than strictly conforming one with it. The second is implemented in a function with a name like `__gnu_rand_optimized`, and then if you `#define __GNU_RAND_OPTIMIZED` before `#include <stdlib.h>`, then that header does `#define rand __gnu_rand_optimized`.

All the C standard requires is that you provide a mode of operation which strictly conforms to it. A platform is allowed to provide configuration options which cause it to be violated in various ways. Strictly conforming code won't turn on those options and so will work as the standard prescribes. If you choose to turn on such an option, that's a non-portable extension, and how it works is between you and the platform, the C standard isn't involved.




Add a new function that modifies behavior of an existing one.

Or add a new function that provides behavior different from the existing one.

The latter is simpler. And safer. And more flexible. And faster, because you don't have a condition to check.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: