shunyo
shunyo

Reputation: 1307

Error - void* - unknown size

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.

Upvotes: 2

Views: 7295

Answers (1)

David Schwartz
David Schwartz

Reputation: 182753

void *end = data + data_size;

Should be:

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

Adding to a void* is a GCC extension.

Upvotes: 12

Related Questions