It's an old-style syntax for parameter lists, supported from K&R C.
See this wikipedia entry.
Question
I'm reading the RPCgen tutorial on Oracle website here http://docs.oracle.com/cd/E19683-01/816-1435/6m7rrfn7f/index.html, but do not understand the example code:
Why "int argc; char *argv[]" is placed outside of the curly braces? When I run the code though, the compiler did not report any error.
/* printmsg.c: print a message on the console */
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
char *message;
if (argc != 2) {
fprintf(stderr, "usage: %s <message>\n",
argv[0]);
exit(1);
}
message = argv[1];
if (!printmessage(message)) {
fprintf(stderr,"%s: couldn't print your
message\n",argv[0]);
exit(1);
}
printf("Message Delivered!\n");
exit(0);
}
/* Print a message to the console.
* Return a boolean indicating whether
* the message was actually printed. */
printmessage(msg)
char *msg;
{
FILE *f;
f = fopen("/dev/console", "w");
if (f == (FILE *)NULL) {
return (0);
}
fprintf(f, "%s\n", msg);
fclose(f);
return(1);}
Solution
It's an old-style syntax for parameter lists, supported from K&R C.
See this wikipedia entry.