Willem said:
Keith Thompson wrote:
) Then perhaps you could explain the point more clearly. It's quite
) possible that I'm missing something you're trying to say.
)
) 1. "typedef" does not define a type.
)
) 2. By "define a type", I mean "create a new type".
)
) 3. "typedef" creates a synonym for an existing type. That existing type
) may, in some cases, be created by the same declaration that includes the
) typedef, but it's not created by the typedef itself.
)
) 4. Since "typedef" does not define a type, "typedef" was a poor name
) choice.
)
) Which, if any, of the above numbered statements do you disagree with,
) and if so, why?
None of the above. I am assuming that in number 2 above, you mean
something specific by "create a new type".
Yes. The type doesn't exist before, or in the absence of, the
declaration. It does exist after, or in the presence of, the
declaration.
For example, if I write:
struct foo { int x; };
then the type "struct foo" exists. If I don't, it doesn't.
The declaration creates the type.
I'm assuming that your point is that a type cannot be a "new" type
when it is _technically_ a synonym of another type.
Yes, except that I fail to see what the word "technically" adds to it.
My argument is that, even though it may be a _technical_ synonym,
it need not be an _abstract_ synonym.
For example:
typedef int length;
typedef int volume;
It doesn't matter if the compiler warns you about mixing them or not.
Length and volume are obviously different types, when viewed as
abstractions. Which is what HLLs are for.
So, in closing, I disagree with what I assume is your definition for
"create a new type".
Ok, so the *intent* of a typedef is to create something that can be
treated as a distinct type, even if the compiler doesn't enforce the
distinction. And if, given the above declarations, I write:
length len = 10;
volume vol = 20;
int z = len + vol;
then my program is logically incorrect, even though there is no error
that a compiler is going to complain about.
If that was Felix Palmen's point, then I agree (and it would have
been nice if he'd simply said so, or at least answered my direct
questions, rather than plonking me.)
My point is simply that that's not what "typedef" really means *in the
language*. And if you want to create a new type and have the compiler
enforce it for you, typedef won't do the job (but a struct will).
(Incidentally, I see that Kenny McCormack and Richard nolastname
have posted in this thread. If I don't respond to what they say,
it's because I haven't read it.)