"Require Function Prototypes" option

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

"Require Function Prototypes" option

跳至解决方案
3,296 次查看
sebasira
Senior Contributor I

Hi to you all!

 

I didn't know where to put this question, I guess here is the best place. I'm working with MCF51QE and CW v6.1 and I was breaking my head looking to "Warning C1801: implicit parameter-declaration." until I discover the "Require Function Prototypes" option in the C/C++ Language panel.

 

I was looking for it, since sometimes I was getting a strange behavior of the firmware, and I was guessing is was due to "implicit parameter-declaration" on some function calls, but I didn't know where.

Now I've check that option and I've found lots (more than 50) of function calls without prototype (#include directive).

 

I was wondering why this option is not "ON" by default and what does the compiler do when the function prototype is missing? From my experience, I can tell that sometimes (maybe always) when the function prototype was missing, the MCU does "what it wants" when it reach that statement or just ignores it.

 

I hope someone can inlightme or clarify my mind.

 

Thanks!

 

 

Sebastian M. Irazabal

标签 (1)
标记 (3)
0 项奖励
回复
1 解答
2,138 次查看
CrasyCat
Specialist III

Hello

Calling a function for which you do not have a prototype is fully legal in ANSI C. This is t reason the option require prototype is not activated by default.

This is a standard ANSI C behavior. If the compiler does not find a prototype for a function it will make assumptions on the type of the parameters passed to the function.

So if you are lucky the application will work as expected, but you may be facing some issues is parameters are passed and read in two different ways.

Basically for numerical value, the compiler assumes that all parameters are of type int when no prototype is detected.

CrasyCat

在原帖中查看解决方案

0 项奖励
回复
4 回复数
2,139 次查看
CrasyCat
Specialist III

Hello

Calling a function for which you do not have a prototype is fully legal in ANSI C. This is t reason the option require prototype is not activated by default.

This is a standard ANSI C behavior. If the compiler does not find a prototype for a function it will make assumptions on the type of the parameters passed to the function.

So if you are lucky the application will work as expected, but you may be facing some issues is parameters are passed and read in two different ways.

Basically for numerical value, the compiler assumes that all parameters are of type int when no prototype is detected.

CrasyCat

0 项奖励
回复
2,138 次查看
TomE
Specialist II

> This is a standard ANSI C behavior.

That is a cause of so many bugs that most code shops and programmers won't write code without prototypes. Whenever I come across code like this I feel I'm driving a car without a seatbelt or a bike without a helmet. Or Brakes, frankly.

I just turn the compiler option on to consider "missing prototypes" to be a fatal error and then fix the code.

Tom

0 项奖励
回复
2,138 次查看
sebasira
Senior Contributor I

Tom, I totally agree with you! And I'm also used to work with it but I could find that option in CF v1 MCUs...

SebaS

0 项奖励
回复
2,138 次查看
sebasira
Senior Contributor I

Thank you very much, CasyCat!!

0 项奖励
回复