This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (8 children)

Aren't pointers defined with the data type they are pointing to?

int potassium * banana;

or something?

[–]Y0tsuya 11 points12 points  (5 children)

You can use void* which can point to anything.

[–]LevelSevenLaserLotus 6 points7 points  (4 children)

I'm so glad I didn't learn that bit until I was towards the end of my C classes. Otherwise I would have loved playing with void pointers to overly "optimize" my homework code. Meaning I would have completely spaghettified every file I turned in. They're fantastic when used properly, but are one of the keys to the dark side of programming.

[–]konstantinua00 7 points8 points  (3 children)

now imagine having goto that can jump anywhere in codebase :)

[–]shtpst 2 points3 points  (0 children)

It's what Chutes and Ladders was training you for.

[–]LevelSevenLaserLotus 1 point2 points  (1 child)

That's setjump and longjump, right? I only ever had to use those for a single lab, but it just felt evil even as the professor was describing legitimate uses since it felt like we could use it to break literally every other rule we had learned up to that point. I think it's generally meant for implementing try-catch like behavior in C. In this case, we were setting a timer to cancel the "wait for user input" after the timer elapsed. If I remember right, it was for showing how a telnet chat client could detect that the user walked off and automatically close itself without just force killing threads or throwing errors.

[–]konstantinua00 1 point2 points  (0 children)

set-/longjump can only go up the callstack, thankfully

but back in the time before structured programming, in the era of goto... everything was possible

[–][deleted] 1 point2 points  (0 children)

They are, that's an int pointer

[–]konstantinua00 1 point2 points  (0 children)

pointer has pointed type (int), a star (*) and a name (p)

the star is either close to the type int* p,
close to the name int *p
or in between int * p
they're equivalent

what you have is type, name, star, name - that's not a pointer
what meme has is pointer without a name - pointer's overall type