由rpcgen示例代码混淆

时间:2014-03-15 15:06:04

标签: c rpc

我正在这里阅读Oracle网站上的RPCgen教程http://docs.oracle.com/cd/E19683-01/816-1435/6m7rrfn7f/index.html,但不了解示例代码:

为什么" int argc; char * argv []"被放在花括号外面?当我运行代码时,编译器没有报告任何错误。

/* 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);}

1 个答案:

答案 0 :(得分:2)

它是K&amp; R C支持的参数列表的旧式语法。

请参阅此wikipedia entry

相关问题