Well first, if you've used C, I'm surprised you
have to ask.
Perhaps you've used it so long that
it has begun to seem normal to you. :^)
The flip side of this is that you have to deal with old mistakes
and with compatibility problems.
For example, I consider the C declarator syntax an
experiment that failed.
- Bjarne Stroustrup, in his SlashDot interview on 2/25/2000.
Due to precedence, it can be difficult to declare complex types:
For instance, what does this declare?:
How about this one, declaring the same type?:
int *(*(*(*x)())[10])();
Sure, its complex too, but you can read the type from
left to right and it makes sense.
x : pointer to function(): pointer to array[10]
of pointer to function(): pointer to int;
No grouping parenthesis are ever required (or allowed); precedence
has nothing to do with it.
With a single declaration, you can declare multiple identifiers, all with different types.
This trips up beginners all the time, people naturally expect:
int* first, next, last;
To declare three pointers to integers.
In meme it does, all identifiers in a declaration must share
exactly the same type:
first, next, last: pointer to int;
[Too few people care about this, but I'm of the opinion that if a language is difficult for a machine to parse, its not so easy for a person either.]
The name is stuck in the middle of the type, when it would ideally be completely seperate from it.
If the name always appears before the type, there is no difficultly with referencing it in its own declaration.
In C:
you are basically forced to name the type twice; it is
both "foo_t" and "struct foo".
typedef
struct foo
{
int data;
struct foo* next;
} foo_t;
[C++ is attempting to fix this, as 'class foo' immediately declares 'foo' as a type.]
While this change doesn't simplify the language to the extreeme, as in Lisp, it is a step in the right direction.
For instance, imagine wanting to write a prototype generator, that takes a source file, and prints the function declaration for each function that is defined. This isn't very easy in C, and its doubly hard if there are K&R functions present.
Go back up to the Meme page.