Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How does c compiler parse composite type without identifier?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading