N
not.here.now
I often change my mind (sometimes back and forth several times) about
whether a given variable should contain a pointer to a structure or
the structure itself, and generally each time I'll have to change
several instances of "." to "->" or vice versa, in the related code.
But the compiler knows when something is a pointer, why can't it let
me write "." in every case and automatically dereference as many times
as necessary?
I've read dmr's article on the history and development of C, and he
talks about a time when "foo->bar" would compile almost regardless of
the type of "foo", with "->bar" just meaning "add a certain offset and
dereference a value of a given type". (Does this mean it wasn't
possible to use the same member name in more than one structure type,
at least for members at different offsets?) Anyway, though, if it was
just a question of backwards compatibility at some point, they could
have deprecated "->" while adding new functionality to ".". So: Is
there a good reason that I'm missing, or is it just that somebody
thought it was a good idea for the programmer to have to make the
difference between pointers and values explicit on every reference?
Because it seems like syntactic salt to me.
whether a given variable should contain a pointer to a structure or
the structure itself, and generally each time I'll have to change
several instances of "." to "->" or vice versa, in the related code.
But the compiler knows when something is a pointer, why can't it let
me write "." in every case and automatically dereference as many times
as necessary?
I've read dmr's article on the history and development of C, and he
talks about a time when "foo->bar" would compile almost regardless of
the type of "foo", with "->bar" just meaning "add a certain offset and
dereference a value of a given type". (Does this mean it wasn't
possible to use the same member name in more than one structure type,
at least for members at different offsets?) Anyway, though, if it was
just a question of backwards compatibility at some point, they could
have deprecated "->" while adding new functionality to ".". So: Is
there a good reason that I'm missing, or is it just that somebody
thought it was a good idea for the programmer to have to make the
difference between pointers and values explicit on every reference?
Because it seems like syntactic salt to me.