Live data from Hacker News

Everything I wish I knew when learning C

tmewett.com

21–30 of 401 posts

Re: Everything I wish I knew when learning C

#27

Earlier quoted context omitted.

The way I got this to stick in my head was to always think of * as dereferencing, and tell myself that int *x; is declaring that the type of *x is int.

It's not just a memorization trick; that's exactly what the statement means. If you do int *x, y; You're saying that both *x and y are integers.

... which is why I never understood why this is the convention rather than

    int* x, y. 
Does somebody know?

Re: Everything I wish I knew when learning C

#29

Decent article. A couple minor points: c89 or c99, not c98. Plain static variables aren't thread-safe by default, true, but there's also _Thread_local

I haven't written actual C code in decades. Did C11 get magic statics with thread-safe initialization like C++11? Does C even have non-trivial initialization of statics local variables?

Re: Everything I wish I knew when learning C

#30
post #27

Earlier quoted context omitted.

It's not just a memorization trick; that's exactly what the statement means. If you do int *x, y; You're saying that both *x and y are integers.

... which is why I never understood why this is the convention rather than int* x, y. Does somebody know?

I don't know for certain, but I suspect it simplified the language's grammar, since C's "declaration follows use" rule means you can basically repurpose the expression grammar for declarations instead of needing new rules for types. This is also why the function pointer syntax is so baroque (`int (*x)();` declares a variable `x` containing a pointer to a function taking no parameters and returning an int).
Post reply on HN