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

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

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

跳至解决方案
1,077 次查看
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 项奖励
回复
1 解答
927 次查看
surabikrishnamu
Contributor II

Hi Erich,

Thank you for the reply

Enabling C++ in Compiler options does detect this

Thanks

Surabi

在原帖中查看解决方案

6 回复数
927 次查看
surabikrishnamu
Contributor II

pastedImage_1.png

0 项奖励
回复
927 次查看
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 项奖励
回复
927 次查看
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 项奖励
回复
927 次查看
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 项奖励
回复
927 次查看
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 项奖励
回复
928 次查看
surabikrishnamu
Contributor II

Hi Erich,

Thank you for the reply

Enabling C++ in Compiler options does detect this

Thanks

Surabi