naseeam
asked on
Is it possible to add pointer to void to unsigned short?
Is it possilbe to add pointer to void to unsigned short?
extern void * memcpy(void *, const void *, size_t);
unsigned char
somefunc_validate(void *data,
unsigned_16 validate_entries,
void *validate_cfg
) {
..
..
unsigned short min_value;
..
memcpy(&max_value, validate_cfg + sizeof(min_value), sizeof(max_value));
What is the result of: validate_cfg + sizeof(min_value)
Above is working code but after compiling with upgraded compiler, following error occurs:
illegal type(s): ptr-to-void '+' unit
extern void * memcpy(void *, const void *, size_t);
unsigned char
somefunc_validate(void *data,
unsigned_16 validate_entries,
void *validate_cfg
) {
..
..
unsigned short min_value;
..
memcpy(&max_value, validate_cfg + sizeof(min_value), sizeof(max_value));
What is the result of: validate_cfg + sizeof(min_value)
Above is working code but after compiling with upgraded compiler, following error occurs:
illegal type(s): ptr-to-void '+' unit
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't switch to c++ compiler. I switched from WindRiver diab 4.2b C langauage compiler to WindRiver diab 5.8.0.0 C languge compiler.
How can this error be fixed without changing functionality? Maybe a typecast is needed.
I don't want to change the pointer arithemetic functionality but I need help in resolving this error.
How can this error be fixed without changing functionality? Maybe a typecast is needed.
I don't want to change the pointer arithemetic functionality but I need help in resolving this error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This works, change it to a char pointer before changing the arithmetic, they have the same internal representation aparently.
http://www.velocityreviews.com/forums/t316242-void-pointer-arithmetic.html
-w00te
http://www.velocityreviews.com/forums/t316242-void-pointer-arithmetic.html
-w00te
int main() {
void* someptr;
int x = 14;
someptr = &x;
unsigned short someshort = 12;
printf("%d", someptr);
//conversion here, its the only important part.
char* temp = (char*)someptr;
temp += someshort;
someptr = (void*)temp;
printf("%d", someptr);
}
Whoops, he beat me to it haha. Sorry bout that JKR.
ASKER
Thanks for all the effort and comments.
gcc would like it and g++ wouldnt I think.
-w00te