This allows the parser to recognize type names which are required for
function prototypes, as well as actual declarations. This also makes it
easy to let the user ask for an explanation of types. For instance:
explain int *(*[])[];
prints
type array of pointer to array of pointer to int.
explain_prologue(char *buf, size_t n, struct cdecl_declarator *d)
{
while (d) {
- if (d->type == CDECL_DECL_IDENT)
+ if (d->type == CDECL_DECL_IDENT) {
+ if (!d->u.ident)
+ return snprintf(buf, n, "type");
return snprintf(buf, n, "declare %s as", d->u.ident);
+ }
d = next_declarator(d);
}
}
.u.pointer.declarator = $2);
}
-direct_declarator: T_IDENT {
+direct_declarator: {
+ ALLOC_STRUCT($$, struct cdecl_declarator,
+ .type = CDECL_DECL_IDENT,
+ .u.ident = NULL);
+} | T_IDENT {
ALLOC_STRUCT($$, struct cdecl_declarator,
.type = CDECL_DECL_IDENT,
.u.ident = $1);