Re: how to define a function pointer variable witout typdef?



Keith Thompson <kst-u@xxxxxxx> wrote:
> Joe Wright <joewwright@xxxxxxxxxxx> writes:

> > 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.

A typedef declaration just creates another identifier, with
all its consequences.
I'd say a typedef name is even less than an alias, more like
a macro definition:
typedef struct s s_t;
/* s_t is an incomplete type here */
struct s { /*...*/ }; /* creates new type, redeclares `s', implicitly
redeclares (redefines) s_t */
/* s_t is a (different) complete type now */
The meaning of a typedef name depends on the context (therefore we
cannot say that it aliases some _particular_ type).

> 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,

[snip]

But then why other declarations are not definitions?
`foo_t' is just another name for `int' type.
struct s;
creates new type and gives it a name `s' (in tag namespace).
Why doesn't this declaration _define_ the identifier `s'?

(Interestingly, `struct s;' does not "define a new type", but "declares
a new type", 6.7.2.3 p.5 and p.7; this is another mystery what
the difference is.)

--
Stan Tobias
mailx `echo siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx | sed s/[[:upper:]]//g`
.



Relevant Pages

  • Re: incorrect warning?
    ... before the typedef for show, ... typedef void (struct thingTag *); ... Since there's been no complete declaration of that type, ... such an incomplete type would be completed later. ...
    (comp.lang.c)
  • [opensuse] pthread compiling problem
    ... declaration as 'typedef long unsigned int pthread_t' ... previous declaration as 'typedef unsigned int pthread_key_t' ... 'typedef int pthread_mutexattr_t' ... a previous declaration as 'typedef union pthread_mutexattr_t ...
    (SuSE)
  • Re: how to define a function pointer variable witout typdef?
    ... I have N869 and it makes no reference to typedef reserving ... A /definition/ of an identifier is a declaration for that ...
    (comp.lang.c)
  • Re: question on structures.
    ...   y *a; ... declaration of y - ... typedef struct x2 x2; ... Why is it wrong to use typedef here? ...
    (comp.lang.c)
  • Re: typedef function pointer
    ... the semantics for typedef is: ... That's the syntax, not the semantics. ... to be an array of 20 ints, the declaration is ... to a function taking to int arguments and returning it, ...
    (comp.lang.c)