this post was submitted on 02 Feb 2024
295 points (96.8% liked)
Programmer Humor
19843 readers
67 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
The fact it's a pointer is part of the type, not part of the variable name. So
int* p
is the way.Then again, at least in C, the mantra is "declaration follows usage". Surely you don't write pointer dereferences as
* ptr
? Most likely not, you most likely write it as*ptr
. The idea behind theint *ptr;
syntax is basically that when you do*ptr
, you get anint
.And with this idea, stuff like function pointers (
int (*f)(void)
), arrays of pointers (int *a[10]
) versus pointers of arrays (int (*a)[10]
) etc. start making sense. It's certainly not the best way to design the syntax, and I'm as much a fan of the Pascal-styled "type follows the identifier" syntax (e.g.let x: number;
) as anyone, but the C way does have a rhyme and a reason for the way it is.