c - what pointer magic is this -
i learning c
. starting understand pointers , type casting. following along guides , examples , ran across declaration:
uint32_t *sp; ... *(uint32_t*)sp = (uint32_t)somevalue;
what happening here? first asterisk mystery me.
breaking down:
*(uint32_t*)sp
basically says treat sp
pointer uint32_t
((uint32_t *)
cast expression), , dereference result.
so,
*(uint32_t*)sp = (uint32_t)somevalue;
means, "take somevalue
, convert type uint32_t
, , store result thing sp
points to, , treat thing though uint32_t
."
note cast on sp
redundant; you've already declared pointer uint32_t
, assignment written as
*sp = (uint32_t) somevalue;
Comments
Post a Comment