"Require Function Prototypes" option

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Require Function Prototypes" option

Jump to solution
2,152 Views
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

Labels (1)
0 Kudos
1 Solution
994 Views
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

View solution in original post

0 Kudos
4 Replies
995 Views
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 Kudos
994 Views
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 Kudos
994 Views
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 Kudos
994 Views
sebasira
Senior Contributor I

Thank you very much, CasyCat!!

0 Kudos