0

Windows doesn't seem to support arc4random. Is there a preprocessor macro I can use to identify if arc4random is supported by the platform I'm compiling for ?

https://man.openbsd.org/arc4random.3

6
  • #if WINDOWS ?.. Commented Mar 1, 2022 at 19:51
  • Not part of the C or C++ Standard library. Don't think it's part of POSIX either. Support is likely to be spotty. Commented Mar 1, 2022 at 19:54
  • What are you going to do if it's not there? And, if there's a suitable approach when it's not there, why not use that approach even if it is there? Commented Mar 1, 2022 at 20:54
  • @PeteBecker Well, since it looks like Windows is the only platform in common use that doesn't provide this function (Linux has it, and macOS, being BSD-based, also has it, for example), using BCryptGenRandom should provide a working solution - on Windows and Windows only. Other than that, what are the options? Presumably, <random> does not satisfy the OP or he would not be looking elsewhere. Commented Mar 1, 2022 at 22:27
  • @PaulSanders — you might be right, but the point of my comment was to encourage the poster to expand the question, not to solicit people’s guesses. Commented Mar 1, 2022 at 23:56

1 Answer 1

2

The manual says it's from <bsd/stdlib.h>, so...

#if __has_include(<bsd/stdlib.h>)
Sign up to request clarification or add additional context in comments.

1 Comment

Hmmm, maybe, that page is for Linux. According to this, macOS, for example, declares it in stdlib.h, although that page is very old and maybe they have moved it to 'conform'. But knowing Apple, probably not. If the OP cares (doubtful!), he would have to check.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.