5

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) 
{

}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Lv99Zubat
  • 853
  • 2
  • 10
  • 27
  • 2
    The syntax from the first code snippet is very old C (pre-ANSI, I think). Meaning of the two snippets is exactly the same. – Daniel Kamil Kozar Mar 10 '15 at 20:15
  • 2
    That's an old style function declaration (circa 1980s). Yes it is the same as the second declaration, but with an implicit return type of `int`. – user3386109 Mar 10 '15 at 20:16
  • 1
    @user3386109, *both* have an implicit return type of `int`. – John Bollinger Mar 10 '15 at 20:20
  • i knew this style by reading C standard. it's indeed an old style and odd. – Jason Hu Mar 10 '15 at 20:22
  • The meaning is not exactly the same: the second one forms a prototype and the first one doesn't. (so in the first case you could later call `A_output(1,2,3);` without requiring a compiler error) – M.M Mar 10 '15 at 20:25
  • http://stackoverflow.com/questions/1630631/alternate-c-syntax-for-function-declaration-use-cases?lq=1 – phuclv Mar 11 '15 at 07:48
  • possible duplicate of [What is this strange function definition syntax in C?](http://stackoverflow.com/questions/3016213/what-is-this-strange-function-definition-syntax-in-c) – phuclv Mar 11 '15 at 07:49

1 Answers1

4

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335