Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on sh.itjust.works

13 replies

programming.dev

Actually void* just points to anything, with no regard to the type of that thing. Pointing to the void is more accurately described by NULL pointer.

97
lemmy.ca

Fair, though I guess my interpretation was that void* is kind of like a black hole in that anything can fall into it in an unsettling way that loses information about what it was?

38

It erases the type of what your pointing at. All you have is a memory location, in contrast to int* which is a memory location of an int

10
frezikreply
midwest.social

"Allow me to combine the worst feature of strong typing with the worst feature of dynamic typing".

32

Result: one of the most if not the most popular programming languages.

27
neoreply
lemy.lol

So, when I want the void to point back at me, do I have to loop over void* or over NULL?
And how many iterations?

7

as many iterations as it takes

void* x = &x;
char* ptr = (char*)&x;

while (1) {
    printf("%d\n", (unsigned int)*ptr);
    ptr--;
}
3

In other words, void refers to the typing of the pointer, not a particular value that might be present at its target.

(But I can see how someone might find it confusing.)

5

You reached the end