Problem using void pointer as a function argument
Posted
by Nazgulled
on Stack Overflow
See other posts from Stack Overflow
or by Nazgulled
Published on 2010-04-07T00:18:30Z
Indexed on
2010/04/07
0:23 UTC
Read the original article
Hit count: 636
Hi,
I can't understand this result...
The code:
void foo(void * key, size_t key_sz) {
HashItem *item = malloc(sizeof(HashItem));
printf("[%d]\n", (int)key);
...
item->key = malloc(key_sz);
memcpy(item->key, key, key_sz);
}
void bar(int num) {
foo(&num, sizeof(int));
}
And I do this call: bar(900011009);
But the printf()
output is:
[-1074593956]
I really need key
to be a void pointer, how can I fix this?
© Stack Overflow or respective owner