[TUHS] C declarations.
krewat at kilonet.net
Fri May 12 08:01:36 AEST 2017
But wouldn't that imply you didn't need to use the * when referencing
the actual value?
For example, if you do this:
The correct way to get the character it's pointing to dereference like this:
If the type was char* (not char)
Wouldn't that imply I wouldn't need the * to dereference the pointer?
On 5/11/2017 5:49 PM, Ron Natalie wrote:
> Bjarne agrees with you. He put the * (and the &) with the type name to emphasize it is part of the type.
> This works fine as long as you only use one declaration per statement.
> The problem with that is that * doesn't really bind to the type name. It binds to the variable.
> char* cp1, cp2; // cp1 is pointer to char, cp2 is just a char.
> I always found it confusing that the * is used to indicate an pointer here, where as when you want to change an lvalue to a pointer, you use &.
> But if we're going to gripe about the evolution of C. My biggest gripe is when they fixed structs to be real types, they didn't also do so for arrays.
> Arrays and their degeneration to poitners is one of the biggest annoyances in C.
>> Am I the only one here who thinks that e.g. a char pointer should be
>> "char* cp1, cp2" instead of "char *cp1, *cp2"? I.e. the fundamental type is "char*", not "char", and to this day I still write:
More information about the TUHS