antirez / sds

Simple Dynamic Strings library for C
BSD 2-Clause "Simplified" License
4.89k stars 473 forks source link

sdscat & sdscatsds in-place? #119

Open drkameleon opened 4 years ago

drkameleon commented 4 years ago

As I've read in the reference and source when you pass an sds string to these two functions, you always have to assign the pointer back.

Is there any workaround to make these functions work in-place? That is: pass them an sds and have it modified? (without changing the object's pointer)

MCRusher commented 4 years ago

I think you could make your own functions that take an sds pointer and assign to it with the original function, like

void sdscat_in_place(sds * sp, char * s){ *sp = sdscat(*sp,s); }

Otherwise I don't think there is any way for the original, which expects a copy of an address, to change the address of the original, which provided the copy.