Error - void* - unknown size

我只是一个虾纸丫 提交于 2019-12-23 04:36:31

问题


This function which I received from a third party contains the following code which does not compile in MS Visual Studio 10. I think there is a casting problem but do not know how to fix this.

void dump_ffmpeg_pad16(FILE *stream, uint32_t timestamp, void *data,
                   int data_size)
{
    unsigned int z=0;
    void *end = data + data_size;
    while (data < end) {
        z = *(unsigned short*)data;
        fwrite(((char*)(&z)), 3, 1, stream);
        data += 2;
    }
}

It has been instructed in their help to compile as C++ code. Thanks for your help.


回答1:


void *end = data + data_size;

Should be:

void *end = ((char *) data) + data_size;

Adding to a void* is a GCC extension.



来源:https://stackoverflow.com/questions/20154575/error-void-unknown-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!