Lv99Zubat
Lv99Zubat

Reputation: 853

Struct declared immediately after function name/parameters but before brackets. Can someone explain this C syntax?

Here is the code:

A_output(message) 
 struct msg message;
{

}

I've never seen syntax like this before. What is that struct definition doing? Is that just another way of specifying the "type" of "message" in the parameter field? So, is it the same thing as this?:

A_output(struct msg message) 
{

}

Upvotes: 5

Views: 350

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 311166

This

A_output(message) 
 struct msg message;
{

}

is an old syntax of a function definition that now is not allowed because the function does not declare the return type. Early by default the return type was int.

As for such function definition

void A_output(message) 
 struct msg message;
{

}

then it is a valid function definition with an identifier list.

From the C Standard (6.9.1 Function definitions)

6 If the declarator includes an identifier list, each declaration in the declaration list shall have at least one declarator, those declarators shall declare only identifiers from the identifier list, and every identifier in the identifier list shall be declared. An identifier declared as a typedef name shall not be redeclared as a parameter. The declarations in the declaration list shall contain no storage-class specifier other than register and no initializations.

Upvotes: 4

Related Questions