Error 1 error C2036: 'const void *' : unknown size file.cpp 111
I don't follow. GCC never complains about void * pointer arithmetic, even on -ansi -pedantic -Wall
. What's the problem?
Here's the code-
struct MyStruct {
const void *buf; // Pointer to buffer
const void *bufpos; // Pointer to current position in buffer
};
...
size_t someSize_t, anotherSize_t;
MyStruct *myStruct = (MyStruct *) userdata;
...
if ( (myStruct->bufpos + someSize_t) >
(myStruct->buf + anotherSize_t) ) { // Error on this line
...
You can't do pointer math on a void *
pointer. Cast oData->bufpos
and oData->anotherConstVoidPtr
to something the compiler knows how to deal with. Since you seem to be looking for sizes, which are presumably in bytes, casting to char *
should work:
if (((char *)oData->bufpos + someSize_t) ...
On the line:
if ( oData->bufpos ...
The type of bufpos is still void*. The compiler doesn't know what that pointer points to, so it gives you that error.
For pointer arithmetic, void* has no size, so taking an offset, or doing other pointer arithmetic doesn't make sense. Cast it to char* if you want to offset it by a number of bytes:
if(((char*)oData->bufpos) + offset ...
Edited after more code/context was given
If you can help it, try to use char* instead of void*. People in C-land will know what you are talking about, because chars are bytes, and you'll save yourself the headache of casting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With