logoalt Hacker News

onre12/09/20242 repliesview on HN

Dunno how this is supposed to be worded, but it's because the "pointerhood" is tied to the variable being declared, not the type itself. This becomes obvious when you declare multiple variables at once.

  char* cat, dog;  /* one char pointer, one char */
  char *cat, *dog; /* two char pointers */

Replies

kevin_thibedeau12/09/2024

The minor problem is that a typedef pointer breaks this pattern:

  typedef foo * FooP;
  FooP a, b; // Both are pointers
Pointer typedefs are misguided but there is no denying that C is inconsistent on whether the '*' is part of the type or not.
teo_zero12/09/2024

Right. It would be nice if C allowed types and variables to be separated, we could even defines arrays like this:

  char[8] buffer;
Alas, it's not the syntax Dennis Ritchie settled upon.
show 1 reply