/* concatenates "bar" after the newly reallocated large enough "FOO" */
memcpy(ZSTR_VAL(foobar) + ZSTR_LEN(FOO), ZSTR_VAL(bar), ZSTR_LEN(bar));
phpcn_u15822017-07-03 11:42:51
void* memcpy(void * destination, const void * source, size_t num);
This operation is to connect "bar"
to the newly reallocated space "FOO"
,
where ZSTR_VAL
returns char*
, ZSTR_LEN
returns int
.
Pointers can be understood as memory addresses. The pointer at the head of the existing space is ZSTR_VAL(foobar)
. Adding the length of space FOO
backwards is the memory address at the end of FOO
space. Start from here. Memory copy, assign the value of bar
(that is, ZSTR_VAL(bar)
), and the length is ZSTR_LEN(bar)
.