Home > Software engineering >  How does c compiler parse composite type without identifier?
How does c compiler parse composite type without identifier?

Time:01-12

Considering the following cdecl examples:

cdecl> explain void(*signal(int, void (*)(int)))(int)
declare signal as function (int, pointer to function (int) returning void) returning pointer to function (int) returning void

cdecl> explain void (*)(int)
syntax error

I'm aware of the 'human' way to interpret void (*)(int) by trying to add imaginary identifier to the proper location, but wonder how compiler systematically determines it, obviously cdecl can't.

CodePudding user response:

The C standard defines how to interpret type names without an identifier in §6.7.7 Type names:

¶2 In several contexts, it is necessary to specify a type. This is accomplished using a type name, which is syntactically a declaration for a function or an object of that type that omits the identifier.

There's also a set of grammar productions that defines how this works.

  • Related