Imagine if for any reason, you want to create several variables, and without using an array, and they must have different names. Logically, you will not create empty variables and set 500 only as needed.
In short, it is possible to generate a variable with the same name without the random use of an array or vector?
If possible, I would like the instantiation logic or C or C++.
I’ve tried in this method (In C), but doesn’t work:
#include <stdlib.h> // for random
#define RANDOM random(100)
int main ( void )
{
int n/**/RANDOM = 5;
return 0;
}
Possibly older compilers work, because they remove the comment. Current compilers consider the comment as a space.
At least on recent GCC, you can use tricks like
On other (or with standard conforming) compilers, you can use
__LINE__instead of__COUNTER__. See Common Predefined Macros of GCC and cpp’s concatenationAlso, you could consider generating such contrived C code, with e.g. m4 or your own generator (which can be a ten line script or a 100K line generator).