Hacker News new | ask | show | jobs
by wrs 2120 days ago
The type of a is

  char *
. Some people (me included) find it clearer to write the type, followed by the variable name. So just as you’d write

  int a
, you’d write

  char* a
.

The fly in this ointment is that C type syntax doesn’t want to work that way. It’s designed to make the definition of the variable look like the use of the variable. A clever idea, but unlike nearly every other language, which BTW is why I think you should really use typedefs for any type at all complicated in C.

For example, the type-then-variable style falls down if you need to declare an array

  int foo[4]
or a pointer to a function returning a pointer to an int

  int *(*a)(void)
(...right?).

So I’m perfectly willing to do it the “C way”, I just find out more readable to do it the other way unless it just won’t work (and then prefer to use typedefs to make it work anyway).

Note that this was rethought for Go syntax.