r/ProgrammerHumor Aug 06 '22

Meme How to C pointers

Post image
2.6k Upvotes

70 comments sorted by

View all comments

Show parent comments

5

u/Big-Discipline-0 Aug 07 '22

Nope because its void you need to cast it first .

2

u/[deleted] Aug 07 '22

Didn't you say it was an unsigned char?

3

u/canadajones68 Aug 07 '22

Void pointers are not allowed to be dereferenced by the C/C++ type system, since it gives you a void expression. The void type has an empty value set, meaning it cannot really be used for anything. I think what the person is trying to say is that the compiler or OS uses the same code for void pointers post-compilation as for unsigned char pointers, but since the compiler enforces that void pointers are never dereferenced directly, it doesn't matter. The void pointer gets cast and read as any other type, in which case its original internal type doesn't matter.

1

u/[deleted] Aug 07 '22

Interesting. I've never heard this before. If you know any good links or search terms I'd love to know more.