Hello everybody,
First of all I thank you all. With the help of you people I have started programming in C. I have completed my first project in C.
Now in my another project, I used the atoi function. I am getting warning & an error like-
MAIN.C(255): warning C206: 'atoi': missing function-prototype MAIN.C(255): error C267: 'atoi': requires ANSI-style prototype
If I use the function without any argument, I get no errors. I have included the function prototypes, some of my code is as..
void data_rcvd_proc() { char *recd_cmd; // command part of the string unsigned char *recd_dat; // data part of the string unsigned char idata tmp_data[17]; ES=0; // disable serial interrupt /* SET DATA */ if (strpos (RxBuffer, '=') != -1){ // if '=' found recd_cmd = strtok(RxBuffer,"="); recd_dat = strtok(NULL,"+"); if(strcmp(recd_cmd, "DELAY_TIME")==0){ // delay_time = atoi(recd_dat); //atoi converts ascii number string into integer } else if(strcmp(recd_cmd, "UP")==0){ // up_time = atoi(recd_dat); //atoi converts ascii number string into integer } else if(strcmp(recd_cmd, "Down")==0){ up_time = atoi(); //atoi converts ascii number string into integer } } }
Pleas help! I cannot understand the problem because in my previous project I HAD EXACTLY USED THE SAME WAY & IT WAS WORKING PERFECTLY , Thanks.
In the above code, I had removed the argument(up_time = atoi();) just for testing. Basically what I want is the controller will receive some numbers from PC in ASCII format. The function should convert them to an integer variable for further processing.
So where are your #include files?
When you use a function from the C runtime library (CRTL), you should also #include the corresponding header file.
atoi() can't be used without argument.
You are only fooling the compiler when you use atoi() without argument and without having included "stdlib.h".
Where??
MAIN.C(255): warning C206: 'atoi': missing function-prototype MAIN.C(255): error C267: 'atoi': requires ANSI-style prototype [...] I have included the function prototypes,
Well, the compiler rather explicitly disagrees with you on that one. And with all due respect, in those cases it's almost always the compiler that's rigt.
So I suggest you do yourself a favour: try to determine the minimal source file that still produces those messages, while you think it shouldn't. Then show us that source file, and together we'll find out that's going on.
I have included the function prototypes, I'm sure he is right he just has not included the RIGHT function prototypes.
Erik
Thank you all for your replies.
Yes, I had included the same function prototypes as in my previous project.
#include <REGX52.h> #include <string.h> #include <intrins.h> //for _NOP_ & like that #include <stdio.h> #include "Functions.h" #include "24C04.h"
Now I included the #include <stdlib.h> as suggested by Per Westermark, & my problem was solved.
But still I can not understand why it was working in my previous project. stdlib is not included in that project, still it is compiled & works in target board.
On one hand, you might have turned off warnings in that other project. When the compiler doesn't have a prototype, it may still manage to send parameters in the correct way or pick up return values in the correct way. The warning is there because the compiler just can't know if you have sent the correct number of parameters, or if you have sent a parameter of the correct type.
Next thing is that you may have had some other header file that included stdlib.h.
Anyway - whenever you get a warning about one of the standard functions, you just have to check which header file that should be used. It's well documented, as it has to be.
Thanks Per, everything is clear to me know. I had not included the stdlib.h file anywhere in my previous project, but I had declared the atoi function in my file.
void init_all(); //initialise all things unsigned char segs2ascii(unsigned char); void read_rtc(); void write_rtc(); char kbhit(); void gps_rcvd_proc(); void data_rcvd_proc(); int atoi(char *string); /* string to convert */ void read_eeprom(); void write_eeprom(); void erase_eeprom(); void SER_init(); void beep(ms);
Thanks again
Don't do that. Always use the standard header files when using standard functions.
Ok Per, actually it was done in my older project. I had seen that way somewhere.
But now I have included stdlib.h file itself.