Skip to contentSkip to conversation

Typecasting a void pointer to unsigned long in zsmalloc.c

DISCUSSION Alex Hogen 2 participants 2 messages Jan 23, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Alex Hogen

author
#1 lore raw
Quoted 3 lines
Quoted 1 line

Shouldn't there be a special type for doing this type of conversion?

That type is "unsigned long" :)

Wouldn't "uintptr_t" be a more explicit type for storing pointer addresses as integers? It seems to me it has the advantage of expressing intent better for us human readers. See <linux/types.h>. Yes, it is currently defined as an "unsigned long."
_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

#2 lore raw
Quoted 5 lines · Alex Hogen
Quoted 3 lines
Quoted 1 line

Shouldn't there be a special type for doing this type of conversion?

That type is "unsigned long" :)

Wouldn't "uintptr_t" be a more explicit type for storing pointer addresses as integers? It seems to me it has the advantage of expressing intent better for us human readers. See <linux/types.h>. Yes, it is currently defined as an "unsigned long."

"unitptr_t" came years, if not decades, after the policy of "a pointer fits into an unsigned long" was the rule (i.e. from the very first release of Linux.

And those crazy _t types are for userspace code, don't use them in the kernel, there's no need.

thanks,

greg k-h

_______________________________________________
Kernelnewbies mailing list
[email protected]
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies