warning: function returns address of local variable [-Wreturn-local-addr]

前端 未结 4 663
Happy的楠姐
Happy的楠姐 2020-12-22 10:58

I get this error when compiling and have checked out other questions here with no further progress:

funciones.c: In function ‘Lyapunov’: ../funciones.

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-22 11:43

    You can use malloc as suggested, but looking at your code better idea would be to have a single static buffer passed to a function to have it's result (since you are using the buffer just once, and then discarding it's data), such that the function signature will be:

    void Lyapunov(int ai, int bi, unsigned char rgb[]);
    

    Then prior the use of the function you will need to define the buffer:

    unsigned char rgb[3];
    

    and then use it in your loop

    Lyapunov(col,linea, rgb);
    

    This way you will not need to worry about any memory leaks (resulting from the function).

提交回复
热议问题