3

These C function signatures are different than I am used to seeing. The code is the following:

struct msg {
  char data[20];
};
struct pkt {
   int seqnum;
   int acknum;
   int checksum;
   char payload[20]; 
};

/**Now LOOK AT THESE FUNCTIONS**/
A_output(message)
  struct msg message;
{
  // blah blah blah
}

B_output(message)
  struct msg message;
{
   // blah blah blah
}

A_input(packet)
  struct pkt packet;
{
   // blah blah blah 
}

The way I know a C function works is return-value name(parameter/s). This looks different. What parameter do the above functions take? What is the return type? How do these functions work?

  • 4
    This is an obsolete syntax used to specify parameter types - and if I remember correctly it hasn't been supported ever since C99. Look up "old-style C parameter list" for details. – templatetypedef Oct 12 '17 at 23:37
  • https://stackoverflow.com/questions/1630631/alternative-kr-c-syntax-for-function-declaration-versus-prototypes – Retired Ninja Oct 12 '17 at 23:40
  • More about this syntax is in https://stackoverflow.com/questions/3092006/function-declaration-kr-vs-ansi . If I am not mistaken, if return type is not set then it is 'int' – VladimirM Oct 12 '17 at 23:40

1 Answers1

1

These definitions are forms of function definitions with an identifier list in parentheses followed by a declaration list. Omitted return types are implied equal to int. Now the C Standard does not allow to omit the return type.

So this function definition

A_output(message)
  struct msg message;
{
  // blah blah blah
}

corresponds to the following definition

int A_output( struct msg message)
{
  // blah blah blah
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335