4 ms·
> For example, removing a prefix the C way would be to add the size of the prefix to the pointer. Surely to do this you'd still have to keep either a reference
by clappski 7y ago
> For example, removing a prefix the C way would be to add the size of the prefix to the pointer.
Surely to do this you'd still have to keep either a reference to the original pointer around or remember the offset so you could `free(str)` with the correct pointer?
- asveikau 7y agoYes, although it's not always your responsibility to do that. Firstly not all strings are on the heap, but ignoring that... If somebody passes you a pointer to a string and you aren't going to hold onto it for a while, you can just add to the pointer and it's no big deal. But yes, if you own the allocation, you need to keep the old pointer too.