passing char buffer to functions and getting the size of the buffer

前端 未结 4 1321
别那么骄傲
别那么骄傲 2021-01-04 10:51

I have set the buffer to size 100. I display the buffer in the main function where the buffer is declared. However, when I pass the buffer to the function and get the sizeof

4条回答
  •  -上瘾入骨i
    2021-01-04 11:27

    You are using the size of the pointer to the buffer (4 bytes), rather than the size of the buffer.

    In C, you have to pass the size of the buffer separately, which is part of the reason buffer overruns happen so easily and frequently.

    void load_buffer(char * buffer, size_t bufSize)
    {    
        ...
    }
    

提交回复
热议问题