This is terrible, but in GNU C you can do it with
* ({ extern int myVariable; &myVariable; }) = myVariable;
Think about this, which can serve in standard C with a helper function:
static int * GlobalMyVariable(void) { return &myVariable; } … *GlobalMyVariable() = myVariable;
Of course, you did not request temporary variables, and this does not use a temporary variable, but at first glance it adds “stuff” to your executable file. However, I compiled a simple use of this with optimization, and the helper function completely disappeared in the generated assembler code. Thus, it is not superfluous code or data when the compiler is optimized correctly.
source share