Проблему легко понять.
В некоторых моих файлах .cpp есть следующий код:
Код: Выделить всё
namespace {
int reg() {
// this code I want to be certainly called
return 1;
}
const int registered = reg();
}
Код: Выделить всё
registered
Код: Выделить всё
reg
But I do need it to be called.
It's important to note that I cannot use this variable in
Код: Выделить всё
main
Код: Выделить всё
main
How to do that without any UB and with guarantee across all the compilers?
I've tried making the variable
Код: Выделить всё
volatile
Код: Выделить всё
__attribute__((used, retain))
Источник: https://stackoverflow.com/questions/781 ... l-variable