View Full Version : "call of function without prototype"
railerobotics
21-01-2006, 14:21
When building a file in Mplab I get an error. It is "call of funtion without protoype." what does this mean and how do I fix it. I am very new to programming.
b_mallerd
21-01-2006, 14:28
It means you need to either define your function or else prototype it.
In a header file you need to type in something like this...
int funtion_name(int parameter_names);
and then in a file you need to actually define the function...
int function_name(int parameter_name)
{
your code goes here;
}
Make sure you have both parts and also make sure you have the header file included in whatever .c file that you are calling the function from.
incase you dont knoe calling = executing your function.
Hope this helps.
Melissa Crues
21-01-2006, 17:45
You can also comment it out depending on what the function is. I ran into this problem on lines 184 and 246 on the users_routine on Kevin Watson's streamline code. When I found where those funtions were defined in the default code, it was in a file not encluded in the streamline one. It turned out that the default definition was replaced by some other code in the new version.
So, I just commented those functions out and it works fine!
devicenull
21-01-2006, 18:43
IIRC it's just a warning. Provided the code gets through the linker fine, you can ignore it, but you should really fix it. You can either define it like b_mallerd said, or simply move the function up in the code, so that the compiler sees it before it tries to call it.
Andrew Blair
21-01-2006, 18:49
Not to get too far off topic, but what is the purpose of a prototype in a header file? Why not just directly call it from a .c file?
devicenull
21-01-2006, 18:53
Not to get too far off topic, but what is the purpose of a prototype in a header file? Why not just directly call it from a .c file?
In our code it doesn't matter to much, but in normal C/C++ you will often have your code divded up into modules. Each module might define say 10 functions. When you prototype something, the compiler can use it, even if it doesn't have the code to do it at that point. It just assumes that it will find the code for the function later on.
So if fileA.h has a prototype to "addThese(int,int,int)", and fileB and fileC both need to use it, they just have to include the header, rather then having three copies of the code for the function.
Andrew Blair
21-01-2006, 19:31
I guess my question is, why do you need the intermediary .h file?
If fileA.c has function "drive(int,int)", and both fileB.c and fileC.c need that function, why not call the function from fileA.c, instead of the prototype from fileA.h?
Maybe I missed your original idea. Does the .h file act as a condenser, #including prototypes from several files, so that instead of calling fileA,B,C.c, you simply call Condenser.h that contains all these prototypes?
Or does it simply act as a place holder, so that you can execute higher level code, while the function is still not actually written? So it calls the function prototype, so it will compile, but so that when you execute it, it does nothing? Thanks!
devicenull
21-01-2006, 19:59
Yes, the .h files condense stuff. In another way, they making changing things easy. For example, last two years I used a file called "defines.h". In it I had stuff like this:
#define DRIVE_LEFT pwm01
#define DRIVE_RIGHT pwm02
This provided two advantages: 1) I could easily change the mappings of our pwm's around, and 2) When it came time to wire the robot, I printed off this file, and it was easy to match PWM's to their function.
The first reason was the main reason to change something. If you need to add another parameter to a function, and its in a .h file, then you change it there, and any code that used the old version would be highlighted.. with it defined in multiple .c files, you could get some strange errors.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.