-
prototyping functions
Ok. Normally, I prototype functions like this:
Code:
//prototype
int function(int var1, char var2, char *point, type variable);
//function
int function(int var1, char var2, char *point, type variable)
{
code;
etc. etc. etc.;
[...]
}
But, I've also seen in some programs this:
Code:
//prototype
int function();
//function
int function(var1,var2,point,variable)
int var1;
char var2;
char *point;
type variable;
{
code;
etc. etc. etc.;
[...]
}
Apparently, both of them work. But my question is: What is the difference?
Thanks!
-
The top one is the "new" ANSI way; the second one is the outdated K&R way.
-
Cool. Ok so, it is the exact same thing? Nothing special between both?
-
Also, if I read the standard correctly, the second form doesn't check for type consistency -- so you can't get warnings of the sort "passing double as argument 2 of function function, expecting char".
It should also be mentioned that in this case "new" means "1989" (if not farther back).
-
Thanks a lot. I'll just keep using the "new" way.
-
> It should also be mentioned that in this case "new" means "1989" (if not farther back).
K&R2 uses the ANSI-style declarations, and that came out in 1988.
-
Prototypes were introduced in some compilers and textbooks before the 1989 ANSI Standard (or 1990 ISO standard) were ratified. New standards do not appear by magic: there is a committee process by which they are developed and quite a few compiler vendors and textbook authors attend committees or receive documentation. Hence they are able to anticipate contents of the standards.