Including the generated "derivative.h"-file

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

Including the generated "derivative.h"-file

2,771 次查看
P_B
Contributor I

Hi all

 

I have a question about including the automatically generated derivative.h-file.

By default the project has this file included in the main.c-file.

But let say you want what is in the derivative.h-file in other .c-files.

 

What I have done is that i moved the include of the derivative.h-file to main.h instead.

And if I needed what was in the derivative.h-fil, I just simply included the main.h-file.

Of course one could just include the derivative.h-file where it's needed, but I thought my way was easier since the main.h-file might already be included in a lot of .c-files.

 

Is my idea ok, or is there something particular I should look out for?

How do you include the derivative.h-file in your projects?

 

/P

标签 (1)
0 项奖励
回复
2 回复数

1,121 次查看
pgo
Senior Contributor V

Dear P_B,

 

As CrazyCat says this is a matter of style.

 

However, a (usual?) convention is that main.h would include declarations/definitions associated with main.c i.e. the functions and data that is "exported" from that module.  This would be extended to other modules in the system e.g. fred.h asociated with fred.c.

 

The above approach helps to make obvious what are the visible 'things' in a module.  Have a search for the idea of "information hiding" which kind-of fits in with this.

 

Given the above, I would suggest if there are a lot of shared definitions that you have a SharedDefs.h or similar to bring together these definitions rather than using "main.h".

 

bye.

0 项奖励
回复

1,121 次查看
CrasyCat
Specialist III

Hello

 

I would directly include derivative.h file in the C source files, which are accessing I/O registers.

For sure you can also include it in main.h, but I am not sure that main.h would be included in more source files.

 

That depends on programmer coding style.

 

 

CrasyCat

0 项奖励
回复