In C parameters are essentially local variables which are initialized with values passed in as arguments. This means they exist only for as long as the function is being executed. Your saveframe
variable ceases to exist once the function exists and with it the value you assigned.
In order to modify values existing outside the function you should use a pointer and modify the value pointed to by that pointer.
Since the value you're working with is a pointer already, you should use a pointer to pointer:
void save_last_frame( uint8_t **saveframe, uint8_t **curframe,
int width, int height, int savestride, int curstride )
You should then modify the code accordingly, replacing saveframe
with *saveframe
. Similarly for curframe
if you also wish for it to be updated by the function.
An example of such "output pointer" argument is endptr
used to record the end of parsed numeric string in strtol()
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…