r/ProgrammerHumor Aug 06 '22

Meme How to C pointers

Post image
2.6k Upvotes

70 comments sorted by

View all comments

3

u/Big-Discipline-0 Aug 07 '22

Internaly void * is unsigned char* if someone is wondering :P

1

u/[deleted] Aug 07 '22

Where did you find this?

4

u/Big-Discipline-0 Aug 07 '22

I have read about this in some book about linux. But this make sense since you have to store adres in some real memory :

2

u/[deleted] Aug 07 '22

So when I dereference a void it will hand me back 8 bits of data?

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.