How do I change the size of void*?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

How do I change the size of void*?

Post by mrjbom »

I'm using a gcc cross-compiler, I'm writing a memory Manager that uses uint64_t to compute addresses, and then converts it to void*(kmalloc does this) for further use.
I get this error "error: cast to pointer from integer of different size".
As I understand the size of void* is 32 bits, how do I change it to 64 bits?
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: How do I change the size of void*?

Post by pvc »

Size of void* depends on the architecture (and/or mode of operation) you are compiling for. It's 4 bytes for x86, 8 bytes for x86-64, etc. It's just a generic pointer. You probably have some problems with compiler flags, which causes it to compile for wrong architecture. Or you messed up something in paltform description files. BTW. you are not supposed to use strictly sized types for address calculcations. There is uintptr_t type used specifically for that purpose. It is supposed to always be the same size as void*. Also, that error you are getting is actually a warning (I think) which has been promoted to error by the use of -Werror compile flag.
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: How do I change the size of void*?

Post by mrjbom »

pvc wrote:Size of void* depends on the architecture (and/or mode of operation) you are compiling for. It's 4 bytes for x86, 8 bytes for x86-64, etc. It's just a generic pointer. You probably have some problems with compiler flags, which causes it to compile for wrong architecture. Or you messed up something in paltform description files. BTW. you are not supposed to use strictly sized types for address calculcations. There is uintptr_t type used specifically for that purpose. It is supposed to always be the same size as void*. Also, that error you are getting is actually a warning (I think) which has been promoted to error by the use of -Werror compile flag.
Oops, I expected that its size depends on the compiler.
Thank you, I will refuse to calculate addresses in uint64_t.
Post Reply