Проблему легко понять.
В некоторых моих файлах .cpp есть следующий код:
Код: Выделить всё
namespace {
int reg() {
// this code I want to be certainly called
return 1;
}
const int registered = reg();
}
Код: Выделить всё
registeredКод: Выделить всё
regBut I do need it to be called.
It's important to note that I cannot use this variable in
Код: Выделить всё
mainКод: Выделить всё
mainHow 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
Мобильная версия