4 ms·
Why is that? I learned C++ first, but spend most of my time now using C. It makes more sense to me that the type should be one thing (struct Bark*) and the iden
by jaydem 6y ago
Why is that? I learned C++ first, but spend most of my time now using C. It makes more sense to me that the type should be one thing (struct Bark*) and the identifier a different thing (p_dog).
Also, a take from Stroustrup since I found it. https://www.stroustrup.com/bs_faq2.html#whitespace https://www.stroustrup.com/bs_faq2.html#whitespace
- bigdict 6y agohttps://eigenstate.org/notes/c-decl https://eigenstate.org/notes/c-decl
- MaxBarraclough 6y agoThe problem is that it doesn't reflect how the C language really works. More specifically, it is misleading in multiple declarations, see the sibling reply at https://news.ycombinator.com/item?id=24109267 https://news.ycombinator.com/item?id=24109267
- Ragnarork 6y agoOne could argue it's wrong to do multiple declarations like that, and the whole argument collapses to mostly a matter of preference.
- MaxBarraclough 6y agoEven if your coding style prohibits multiple declarations, you still don't escape the fact that in C, the asterisk binds to the variable identifier, not to the type. It crops up again in the function pointer syntax: void *(*foo)(int *); foo is a pointer to a function which accepts a pointer-to-int and returns a pointer-to-void. ( Taken from https://www.cprogramming.com/tutorial/function-pointers.html https://www.cprogramming.com/tutorial/function-pointers.html )
- tgb 6y agoThanks, this is the best example I've seen.
- saagarjha 6y agoYou can call a feature of a language misguided, but you can't call it wrong; that's just how C does identifiers. Sure, in your "cut out the parts of C that don't fit into my model" you can make it work, but that's not C.