I am just trying to understand this C code ( not trying to achieve any functional goal by the program). This compiles using gcc. Is this main in main(int a, char *argv[] ) format? Is it permissible to declare anything beween argument and function body (similar to char *a; here)?
#include <stdio.h>
main(u,_,a)
char
*a;
{
//printf("%s\n",_,a);//just to help debugging
//printf("%d\n",u); //just to help debugging
}
This is an old, obsolete way of writing C functions.
In an ancestor language of C, there were no types: all variables contained a machine word. So a function definition would start like this:
C as it used to be, known as āK&R Cā from the authors of the seminal book about C (Brian Kernighan and Dennis Ritchie) added types in a form that looked like variable declarations, and were between the list of function parameters and the code of the function.
In K&R C, if a type is
int
, then in many places it can be omitted. For a function parameter, you can omit the type declaration line altogether.ANSI C was standardized in 1989, and one of its main innovations was function prototypes. In proper ANSI C, you declare all functions before use and you declare the types of all arguments.
C compilers still support the old form for legacy code. (If they conform to the 1989 C standard, they have to.) There isn't much legacy code left after more than 20 years, so you won't find such code often.
(Note that this is not the right type for
main
. I think Gcc will warn you about that but you may have to turn the warning settings up.)