In the following:
struct adt { void * A; };
int new_adt(const void * const A)
{
struct adt * r = malloc(sizeof(struct adt));
r->A = A;
}
I get:
warning: assignment discards qualifiers from target pointer type
I know I can use
memcpy(&(r->A), &A, sizeof(void *));
to get around this, but I have to ask: is there an alternative?
Using const void * const, I pretend that no changes will be made to the input. Also, now that I'm thinking about it, that's const void *enough, isn't it? (Since I cannot change the pointer so that it affects the caller)
Thanks for taking the time to read.
source
share