Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

prototype

// 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

#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

Any suggestions/hints are appreciated!

like image 973
jasonaburton Avatar asked Mar 02 '12 23:03

jasonaburton


2 Answers

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. Otherwise your function declaration does not count as a valid prototype.

void screen_init(void); 
like image 78
makes Avatar answered Sep 20 '22 12:09

makes


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. Good luck.

like image 24
ProbHunter Avatar answered Sep 17 '22 12:09

ProbHunter