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

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

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

Jump to solution
1,758 Views
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.

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,499 Views
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

View solution in original post

0 Kudos
Reply
6 Replies
1,500 Views
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 Kudos
Reply
1,499 Views
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 Kudos
Reply
1,499 Views
CrasyCat
Specialist III

Hello

 

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

CrasyCat

0 Kudos
Reply
1,499 Views
100asong
Contributor I

MCU:9s12x.

CodeWarrior:5.9.0

0 Kudos
Reply
1,499 Views
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

1,499 Views
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 Kudos
Reply