K
Keith Thompson
Joe Wright said:Keith said:No, it doesn't create an object in memory. Neither does a functionJoe Wright said:Keith Thompson wrote: [snip]
Typedefs are a bit odd in that a typedef doesn't actually create a
new type, merely an alias for an existing type. But a typedef is a
definition because the thing it creates is the alias, not the type.
And now we wait for the experts to point out my errors.
I suppose a typedef is not a definition. This because it does not
create an object in memory. It's another case of C overloading the
English language. Odd, isn't it that '#define X 2' is not a definition
either.
definition. A definition, as I understand it, is a declaration that
creates the named entity, rather than merely referring to an entity
that's created elsewhere. The entity doesn't have to be an object.
Nice side step. In what way is a typedef a declaration creating a
named entity?
The entity it creates is a named alias for an existing type. An
"entity", as I'm using the term, doesn't have to be something that
occupies memory space; it's just something that can be named.
Given:
typedef int foo_t;
"foo_t" is the name of an entity (the alias) that wouldn't exist
without the typedef. Without the typedef, there isn't anything called
"foo_t". (The type int does already exist, but that's not what's
being declared.) By contrast,
extern int foo;
is not a definition because the entity "foo" (which in this case is an
int object) exists with or without the declaration. (If an extern
declaration created a new name, I'd probably argue that it's a
definition that creates an alias for an existing object, but all it
does is refer to an existing object with an existing name.)