i define a structure that contains a constant member.
the problem is, when i use malloc
to make such a struct, i fail to initialize its const member, for example:
struct C {
int* const p;
};
int main()
{
int i = 0;
struct C s = { &i }; // ok
struct C* d = (struct C*)malloc(sizeof(struct C));
d->p = &i; // error
free(d);
return 0;
}
is there any way i can do it?
ps: i use MinGW GCC.