Effective type

suggest change

The effective type of a data object is the last type information that was associated with it, if any.

// a normal variable, effective type uint32_t, and this type never changes
uint32_t a = 0;

// effective type of *pa is uint32_t, too, simply
// because *pa is the object a
uint32_t* pa = &a;

// the object pointed to by q has no effective type, yet
void* q = malloc(sizeof(uint32_t));
// the object pointed to by q still has no effective type,
// because nobody has written to it
uint32_t* qb = q;
// *qb now has effective type uint32_t because a uint32_t value was written
*qb = 37;

// the object pointed to by r has no effective type, yet, although
// it is initialized
void* r = calloc(1, sizeof(uint32_t));
// the object pointed to by r still has no effective type,
// because nobody has written to or read from it
uint32_t* rc = r;
// The read is valid because calloc produced an all-bits-zero representation,
// which is a valid uint32_t. A read uses the lvalue type for that access,
// but it does not give the object a lasting effective type. A store or
// memcpy does.
uint32_t c = *rc;

// the object pointed to by s has no effective type, yet.
void* s = malloc(sizeof(uint32_t));
// the object pointed to by s now has effective type uint32_t
// because the value of *q, whose effective type is uint32_t, is copied into it.
memcpy(s, q, sizeof(uint32_t));

Observe that the memcpy does not need a uint32_t * to the destination. Copying the representation of another uint32_t object is enough to set the effective type.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents