Click to See Complete Forum and Search --> : Does this conform to the ISO standard?


Hnefi
February 24th, 2006, 05:27 AM
Hi. I was helping a friend yesterday who needed to set up a compiler on her home computer in order to do some labwork for a course in OS programming.

I looked through part of the code for the lab skeleton because it refused to compile, and I found many strange things. One thing, however, made me hesitate as to whether this lab skeleton even conforms to the standard at all, namely the following:
main(argc, argv)
int argc;
char *argv[];
{
<stuff>
}
Note the lack of return type for main, the lack of type for the parameters and the odd decision to specify the headers between the parameter list and the function definition. Is this even allowed in C or does it cause undefined behaviour?

Paul McKenzie
February 24th, 2006, 05:38 AM
Hi. I was helping a friend yesterday who needed to set up a compiler on her home computer in order to do some labwork for a course in OS programming.

I looked through part of the code for the lab skeleton because it refused to compile, and I found many strange things. One thing, however, made me hesitate as to whether this lab skeleton even conforms to the standard at all, namely the following:
main(argc, argv)
int argc;
char *argv[];
{
<stuff>
}
Is this for 'C' (not C++)?

If this is 'C' this is old-style K&R function definition, and is valid (but hardly any programs use this, except for those 'C' programs that were written somehwere around 20 or so years ago).

None of this is valid C++, however. You need a return type for main(), and old-style K&R function headers are forbidden.

Regards,

Paul McKenzie

Hnefi
February 24th, 2006, 06:34 AM
I see. Yes, judging from the rest of the code, it's C. Your observation that this looks like old code probably explains why the rest of the source seems so arcane in some places. We'll see how I'll be able to tackle it when it's time for me to take the course next year.

Thanks for your help.