Пожалуйста, рассмотрите следующий код.
typedef struct{
int field_1;
int field_2;
int field_3;
int field_4;
uint8_t* data;
uint32_t data_size;
} my_struct;
void ext_function(inalterable_my_struct* ims, ...);
Я хочу разрешить ext_function
(написанный третьей стороной) изменять только field_3
и field_4
в my_struct
. Поэтому я делаю следующее:
typedef struct{
const int field_1;
const int field_2;
int field_3;
int field_4;
const uint8_t* data;
const uint32_t data_size;
} inalterable_my_struct;
void ext_function(inalterable_my_struct* ims, ...);
Безопасно ли указывать указатели между my_struct
и inalterable_my_struct
перед вызовом ext_function
(как показано ниже)?
void call_ext_function(my_struct* ms){
inalterable_my_struct* ims = (inalterable_my_struct*)ms;
ext_function(ims, ...);
}