【问题标题】:'main' declared as function returning a function'main' 声明为返回函数的函数
【发布时间】:2014-02-25 18:58:03
【问题描述】:

上周在这里问了一个关于有两个 main() 的问题。昨晚试了一下,出现了这个错误。请看一看。 我的头文件(top.h):

#ifndef TOP_H_
#define TOP_H_
#include <stdio.h>
#include <string.h>
#define onemain main()
#define twomain main()
void print();
#endif /* TOP_H_ */

c源文件一(one.c):

#include "top.h"
void print();
int onemain()
{
    print();
    return 0;
}
    void print()
{
printf("hello one");
}

c源文件二(two.c):

#include "top.h"
void print();
int twomain()
{
    print();
    return 0;
}
void print()
{
printf("hello two");
}

谢谢你们!

【问题讨论】:

  • 你能把相关的错误拉出来吗?仅将错误放在图像中通常是不受欢迎的。

标签: c function main


【解决方案1】:
#define onemain main()
int onemain()

这将被预处理为:

int main()()

您需要删除其中一对括号。

【讨论】:

    猜你喜欢
    • 2013-03-16
    • 2019-09-22
    • 1970-01-01
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多