简体   繁体   English

错误:没有以前的功能原型。 为什么我收到此错误?

[英]Error: No previous prototype for function. Why am I getting this error?

// screen.h // screen.h

#ifndef screen_h
#define screen_h

#define MAC  1
#define WIN  2
#define LNX  3

#ifdef PLATFORM 
# undef PLATFORM 
#endif

#define PLATFORM MAC

void screen_init();

#endif

// screen.c // screen.c

#include <string.h>
#include <stdlib.h>

#include "screen.h"

#if PLATFORM == MAC

#include <curses.h> 

void screen_init(){
    erase();
}

#endif

I don't understand why it is not seeing my prototype in screen.h 我不明白为什么它没有在screen.h中看到我的原型

Any suggestions/hints are appreciated! 任何建议/提示表示赞赏!

ISO/IEC 9899:TC2 - 6.2.1.2: ISO / IEC 9899:TC2 - 6.2.1.2:
A function prototype is a declaration of a function that declares the types of its parameters. 函数原型是声明其参数类型的函数的声明。

An empty argument list in a function declaration indicates that the number and type of parameters is not known. 函数声明中的空参数列表表示参数的数量和类型未知。 You must explicitly indicate that the function takes no arguments by using the void keyword. 您必须使用void关键字明确指出该函数不带参数。 Otherwise your function declaration does not count as a valid prototype. 否则,您的函数声明不会被视为有效的原型。

void screen_init(void);

I met this similar error minutes ago. 几分钟前我遇到了类似的错误。 After i'd added the relatived function declaration in head file, error's gone. 在头文件中添加了相关函数声明后,错误消失了。
Also, some said that canceling the compile option '-Wmissing-prototypes' should work, but i didn't have tried that. 另外,有些人说取消编译选项'-Wmissing-prototypes'应该有效,但我没有尝试过。 Good luck. 祝好运。

I just had this problem today. 我今天刚遇到这个问题。

I defined a function that just used internally 我定义了一个内部使用的函数

void func(void) {
}

int main(void) {
    func();
}

This will give me that warning. 这会给我这个警告。 I had to add the prototype at the beginning of the file to get rid of the warning. 我不得不在文件的开头添加原型以消除警告。

void func(void);

void func(void) {
}

int main(void) {
    func();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM