Why learn C? (O'Reilly Radar)
Posted Jun 29, 2012 23:38 UTC (Fri) by
HelloWorld (guest, #56129)
In reply to:
Why learn C? (O'Reilly Radar) by tjc
Parent article:
Why learn C? (O'Reilly Radar)
I don't know why I'm even responding to this, given that you're calling me a troll without any justification.
Anyway, the main problem with C is its declaration syntax. Let's take a declaration like
void (*signal(int, void(*)(int)))(int);
This is ugly for two reasons. One is that parenthesis are required to distinguish
void *(int) from
void(*)(int). The other is that the tokens that describe the function's return type are split up: the
void(* in the beginning and the
)(int) in the end belong together, which is harder to figure out than necessary. Using a postfix pointer declarator fixes the first problem but not the second:
void signal(int, void*(int))*(int);
This is fixable by using another syntax for simple declarations:
i int; instead of
int i;. That would lead to a declaration like this:
signal(int, *(int)void) *(int) void
This also offers the advantage that the name being declared is always at the beginning of the line. It also makes preprocessor macros that involve declarations easier to write.
Another problem with the C syntax is that in function parameter declarations, foo[] means the same as foo*, while everywhere else it doesn't. People keep confusing arrays and pointer due to this (though the implicit conversion from foo[] to foo* also promotes this).
I also find it ugly that while both :? and if/else exist, there is only a switch statement and not a switch expression.
And just to be clear: the C syntax is actually not the greatest of C's problems. The lack of sane type and module systems is a much greater burden.
(
Log in to post comments)