By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

'void *' : unknown size

P: n/a
I'm trying to do some pointer manipulation and can not avoid using void * as
the type declaration. I get this error message : error C2036 : 'void *' :
unknown size though. Is there a compiler option or a way to tell the compiler
the size of void * to avoid this?

On a side note, when using W2003, I have this site defined as a trusted site
but the "new question" dialog is blocked as a popup (I had to go to a W2000
distribution). Popup blocked is disabled for Trusted sites, any idea how to
really disable the popup blocker ?

Thanks.
Betsy.
Mar 24 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> I'm trying to do some pointer manipulation and can not avoid using void *
as
the type declaration. I get this error message : error C2036 : 'void *' :
unknown size though. Is there a compiler option or a way to tell the
compiler
the size of void * to avoid this?


Your problem is that pointer arithmetic is dependent on the size of what the
pointer is pointing to:

int myArray[12];
int * test = &myArray[0];
test++;

the ++ operation moves the pointer not 1 byte, but sizeof(*test) bytes so
thaty it points to myArray[1];
void * does not have a type, so the compiler does not know what it should do
when + and - are applied. It does not point to anything that can be used for
size.

the solution is to cast to so what you mean it to be.
If you really want to do pointer aritmetic on a byte by byte basis, you have
to cast your pointer to char *.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Mar 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.