A puzzled question:One project can been builded okay without including A.h headfile in Main.c.

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

A puzzled question:One project can been builded okay without including A.h headfile in Main.c.

跳至解决方案
2,707 次查看
100asong
Contributor I

Dear All:

I can build and link This project. But the main.c file call test() function, and test() funcion is located in A.c file. Test() function is defined in A.c and declared in A.h. I find main.c not including A.h And all files except A.c don't include A.h file.

I can not understand:why the project can been builded and linked, since that we didn't write A.h sentence in project.

Please help me.

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

Hello

 

The compiler follows the C89 standard, which allows you to invoke a function even though you did not declare a prototype for this function earlier.

 

You can configure the compiler to generate a message in that case.

 

The option to be used depends on the MCU you are targeting. For HCS08 or HCS12, HCS12X you can use the option -Wpd.to get a  warning message when a prototype is missing.

 

CrasyCat

在原帖中查看解决方案

0 项奖励
回复
6 回复数
2,449 次查看
CrasyCat
Specialist III

Hello

 

The compiler follows the C89 standard, which allows you to invoke a function even though you did not declare a prototype for this function earlier.

 

You can configure the compiler to generate a message in that case.

 

The option to be used depends on the MCU you are targeting. For HCS08 or HCS12, HCS12X you can use the option -Wpd.to get a  warning message when a prototype is missing.

 

CrasyCat

0 项奖励
回复
2,448 次查看
100asong
Contributor I

Hi,Dear Sir,

      

      1. Just like what you said, though build and link okay,  a warning: C1801: Implicit parameter-declaration for 'test' ... will occur.

      2. The whole project is from my friend. I want to create one file BB.c and BB.h,and define MyFunc in BB.c and declared it in BB.h, and write include "BB.h" in BB.c, and then call MyFunc in main.c, not include BB.h in main.c. But build wrong, can not finish.

     3. How to implement  option -Wpd in setting window?

 

Thanks.

      

0 项奖励
回复
2,448 次查看
CrasyCat
Specialist III

Hello

 

- Which CPU are you targeting (HC08, HC12, Coldfire, ..)
- Which version of CodeWarrior are you using?

CrasyCat

0 项奖励
回复
2,448 次查看
100asong
Contributor I

MCU:9s12x.

CodeWarrior:5.9.0

0 项奖励
回复
2,448 次查看
CrasyCat
Specialist III

Hello

 

To activate the option which generate an error message when function prototype is missing follow these steps:

    - Open your project in CodeWarrior

    - Open the Target Settings dialog (press ALT+F7)

    - Go to Target > Compiler for HC12 panel.

    - Click on the Options button.

    - Switch to the Message tab.

    - Scroll down in the list box and check Error for implicit parameter declaration.

    - Click OK to close the HC12 Compiler Option settings dialog.

    - Click OK to close the Target Settings dialog.

 

CrasyCat

2,448 次查看
rocco
Senior Contributor II

Hi Tom,


. . .  and then call MyFunc in main.c, not include BB.h in main.c.      

If you wish to call "MyFunc" from "main.c", then you should include "BB.h" in "main.c" as well. That is the purpose of a .h file.

 

A good book on "C" is called for.

0 项奖励
回复