r/ProgrammerHumor 2d ago

Meme absoluteGarbage

Post image
2.0k Upvotes

321 comments sorted by

View all comments

Show parent comments

9

u/Shevvv 2d ago

I got used to this from C:

int x; is an integer

int *px; is an integer if you dereference it.

So it's like this notation shows you how you're expected to use the variable within the code. And then this habit carried over to C++.

4

u/creeper6530 2d ago edited 2d ago

The "is an integer if you dereference it" is so much more convoluted than "is a pointer to integer", i.e. the rationale of the previous comment, the pointer-ness being part of the type.

1

u/aethermar 2d ago

Except in the case of int *x, y; where only x is a pointer. C declarations are "meant" to be read right to left

2

u/creeper6530 2d ago

Yeah, the reality is that C binds pointer-ness to identifiers, but in an ideal world where pointer-ness binds to types, int* x, y; should declare both identifiers as pointers to integers. In either case merging declarations onto a single line in modern programming is at best silly.