cgccerror-handlingprogram-entry-point

why "int main(anything_you_type)" doesnt produce any error?


Here I have written my name in main argument declaration but still this program works and did not give any warning.

#include <stdio.h>
int main(Mr32) 
{
    printf("why this works?");
    return 0;
}

Whenever I write anything in place of mr32 , The code still works. I really don't know why this is happening. As per C programming standard this is wrong, right?

Edit : I have tried -Wall but it does not give any warning.

I think here it should be error, because i am not doing as standard C function definition declaration

In c every function definition must follow this format

return-type function_name ( arg_type arg1, ..., arg_type argN ); 

This should also appy to main() right ..??

Okay -Wextra shows warning that mr32 is by default int.

Then why is the default type of any argument in main() an int?


Solution

  • In the K&R C definition a parameter without type defaults to int. Your code then corresponds to

    int main( int Mr32 ) {
        printf("why this works?");
        return 0;
    }
    

    Take a look at this answer for the details: C function syntax, parameter types declared after parameter list

    Update

    To summarize: in C89 K&R declarations are still supported

    Note

    Although this is supported I would never use it: code should be readable