J
Jon
Keith said: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.
The programmer can declare a type, but only a compiler can create one.
The declaration is the specification used by the compiler. The programmer
can then later "define" (specify to the compiler to create an instance
of ) a type. (I don't like using "define" this C way, FWIW).
// foo.h
struct foo { int x; }; // type declaration
// foo.c
foo foo_instance; // type "defintion" (actually, type instantiation)
For example, if I write:
struct foo { int x; };
then the type "struct foo" exists.
Not really. It's just declared.
If I don't, it doesn't.
The declaration creates the type.
Not really. That's probably why it's called type declaration and not type
creation. "Introduces" a new name may work.
(That goes without saying).
Yes, except that I fail to see what the word "technically" adds to it.
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).
And enum and union will also.