Generate a random number using the C Preprocessor

后端 未结 3 822
暖寄归人
暖寄归人 2020-12-09 18:00

I would like to generate a random number or string using the C Preprocessor ... um ... I don\'t even know if this is possible, but I am trying to create var

3条回答
  •  忘掉有多难
    2020-12-09 18:39

    Don't do this in C. You'll end up confusing people. If you need to create variables on the fly, use malloc and realloc and maintain an array of their values.

    To answer your question, no. The preprocessor doesn't include a random number generator. You can generate random numbers at runtime (with rand()), but if you really need them at compile time, you'll have to write your own preprocessor and run your code through it. Or you could just use 4, which was randomly determined by a roll of a fair 100 sided die.

提交回复
热议问题