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,327件の閲覧回数
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 解決策
1,177件の閲覧回数
surabikrishnamu
Contributor II

Hi Erich,

Thank you for the reply

Enabling C++ in Compiler options does detect this

Thanks

Surabi

元の投稿で解決策を見る

6 返答(返信)
1,177件の閲覧回数
surabikrishnamu
Contributor II

pastedImage_1.png

0 件の賞賛
返信
1,177件の閲覧回数
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 件の賞賛
返信
1,177件の閲覧回数
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 件の賞賛
返信
1,177件の閲覧回数
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 件の賞賛
返信
1,177件の閲覧回数
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 件の賞賛
返信
1,178件の閲覧回数
surabikrishnamu
Contributor II

Hi Erich,

Thank you for the reply

Enabling C++ in Compiler options does detect this

Thanks

Surabi