cas: Thanks for the explanation. Compiling my code with GCC 4.2.4. with option -W only gives these warnings:
Code:
gcc -W xyz.c
xyz.c: In function ‘main’:
xyz.c:4: warning: type of ‘x’ defaults to ‘int’
xyz.c:4: warning: type of ‘y’ defaults to ‘int’
xyz.c:4: warning: type of ‘z’ defaults to ‘int’
and compiling with -Wall only warns about the return:
Code:
gcc -Wall xyz.c
xyz.c:4: warning: return type defaults to ‘int’
xyz.c: In function ‘main’:
xyz.c:9: warning: ‘return’ with no value, in function returning non-void
I finally found some info about "old style" function declarations and calls in Appendix A7.3.2 and A8.6.3 of my K&R second edition , but nothing specific about main. It seems that there is nothing built into the compiler that restricts the parameter list of main to be only (void) or (int, char**). Is there anything actually written in the standard that requires main to only those two parameter lists?
Obviously I agree that this is horrible programming style. I only stumbled across it while trying to understand some intentionally obfuscated code.
Brafil: apparently you can declare main to be anything you want. It may be nonstandard, but the compiler doesn't seem to care. Can you compile this in MSVC?
Code:
#include <stdio.h>
main(x,y,z,a,b) double y; char z; char *a; double b; // x will default to int
{
if( x == 1 )
printf("Hello world\n");
else
printf("x = %d, y = %f, z = %c, a = %s, b = %f\n",x,y,z,a,b);
y = 2*x;
if(x == 5)
return;
else
main( x+1,y,'c',"hello",3.3*x );