Void * error (error c2036: 'void * ': Unknown size)

Source: Internet
Author: User

This error is caused by a void pointer. If it is another type, this error will not occur. My error is due to the offset operation on the void * pointer, to write data, the original code is as follows:

Void * halfbi;

Int M = n = I = 0;

Halfbi = globalalloc (ghnd, dwbmbitssize/2 );

While (I <1024*768)

{

Memcpy (halfbi + M, lpbi + sizeof (bitmapinfoheader) + dwpalettesize + N, 32 );

M = m + 32;
N = N + 64;

}

 

In this case, error c2036: 'void * ': Unknown size occurs. Why?

Next, let me talk about my opinion: Because the variable defined by my portal is void *, void is not fixed to the number of bytes as a unit (INT type is 4 bytes (on C ++ )), so if halfbi increment or decrease the offset operation, the system will not know how many bytes your pointer should offset by adding 1, which leads to address uncertainty, of course, the problem can be solved after the problem is found. The problem can be completely solved by forced conversion of excitation types. The modified code is as follows:

Char * halfbi;

Int M = n = I = 0;

Halfbi = (char *) globalalloc (ghnd, dwbmbitssize/2 );

While (I <1024*768)
{
Memcpy (void *) halfbi + M, lpbi + sizeof (bitmapinfoheader) + dwpalettesize + N, 32 );
M = m + 32;
N = N + 64;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.