HCS12 compiler does not throw an error for function arguments number mismatch in declaration and definition

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

HCS12 compiler does not throw an error for function arguments number mismatch in declaration and definition

Jump to solution
1,412 Views
surabikrishnamu
Contributor II

A function is declared with 2 arguments, but the definition has only 1 argument

The HCS12 compiler does not throw an error or warning

CodeWarrior IDE version 5.9.0 build 5294 

0 Kudos
Reply
1 Solution
1,262 Views
surabikrishnamu
Contributor II

Hi Erich,

Thank you for the reply

Enabling C++ in Compiler options does detect this

Thanks

Surabi

View solution in original post

6 Replies
1,262 Views
surabikrishnamu
Contributor II

pastedImage_1.png

0 Kudos
Reply
1,262 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hello,

can you please send me a demo project of this problem?

Thanks!


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,262 Views
surabikrishnamu
Contributor II

pastedImage_1.png

I have a main.c file which calls the function add

The function add is declared in add.h and defined in add.c

I have added all these files in the project

I don't get an error when I compile the project

0 Kudos
Reply
1,262 Views
surabikrishnamu
Contributor II

Hi Alice,

The declaration in add.h has 2 arguments

The definition in add.c has just 1 argument

When I call the function in main.c, I am passing 2 arguments which would result in error

I was expecting an error or warning "wrong number of arguments"

0 Kudos
Reply
1,262 Views
BlackNight
NXP Employee
NXP Employee

Hi Surabi,

I have to disagree that this is a compiler bug/error. You are missing to include

#include "add.h"

inside add.c.

According to the C language, the compiler won't be able (and shall not) produce an error for this. The linker has no chance to detect this neither. If you want to catch something like this, you would have to compile your sources in C++ mode.

I hope this helps,

Erich

0 Kudos
Reply
1,263 Views
surabikrishnamu
Contributor II

Hi Erich,

Thank you for the reply

Enabling C++ in Compiler options does detect this

Thanks

Surabi