模块化 [英] Modularisation

查看:82
本文介绍了模块化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人能推荐一个关于C / /
程序模块化成不同文件的好wbeppage吗?


感谢大家

Steffen

Hi,

can anyone recommend a good wbeppage concerning modularisation of C
programs into different files?

Thanks to all of you
Steffen

推荐答案

" Steffen Loringer" < ST ************** @ freenet.de>在留言中写道

新闻:3q ************ @ news.dfncis.de ...
"Steffen Loringer" <st**************@freenet.de> wrote in message
news:3q************@news.dfncis.de...
任何人都可以推荐一个好的wbeppage将程序模块化为不同的文件?
can anyone recommend a good wbeppage concerning modularisation of C
programs into different files?




但是问题是什么?通常,这是通过将代码中的或多或少
独立部分分成单独的文件来完成的。只是。当然

可能涉及相当多的编码,而不仅仅是复制''n''pasting ......

但就C而言,问题是什么? ?


Alex



But what is the problem? Normally this is done by separating more or less
independent portions of the code into separate files. Just that. Of course
that may involve quite some coding, not just copy''n''pasting...
But as far as C goes, what''s the problem?

Alex


没有真正的问题。但是可能存在良好编码的规则等......

我将我的功能分开按程序的功能部分。进入标题

* .h和源* .c文件。

我必须为每个* .h和* .c包含许多库,这是否使我的

最后可执行文件更大?


感谢您的回复,Alexei!


Alexei A. Frounze schrieb:
There is no real problem. But there may be rules for good coding etc...
I separated my functions "by function part of the program" into header
*.h and source *.c files.
I have to include many libraries for each *.h and *.c, does this make my
executable bigger at the end??

Thanks for your reply, Alexei!

Alexei A. Frounze schrieb:
" Steffen Loringer" < ST ************** @ freenet.de>在留言中写道
新闻:3q ************ @ news.dfncis.de ...
"Steffen Loringer" <st**************@freenet.de> wrote in message
news:3q************@news.dfncis.de...
任何人都可以推荐一个好的wbeppage将程序模块化为不同的文件?
can anyone recommend a good wbeppage concerning modularisation of C
programs into different files?



但是问题是什么?通常,这是通过将代码的更多或更少的独立部分分离成单独的文件来完成的。只是。当然
可能涉及到相当多的编码,而不仅仅是复制''''''... ...
但就C而言,问题是什么?
Alex


But what is the problem? Normally this is done by separating more or less
independent portions of the code into separate files. Just that. Of course
that may involve quite some coding, not just copy''n''pasting...
But as far as C goes, what''s the problem?

Alex






* .h应该包含打算供调用者使用的公共信息,例如:

- 宏

- 类型定义

- 内联函数(您可能需要将它们声明为静态内联 -

取决于我猜的编译器。

- externs

* .c应该包含其他所有内部的,不会暴露给

外部世界。

这就是.h vs .c去。

但是你也应该在语义上分开代码,放入不同的。?

文件代码用于不同的东西,例如:

- 输入/输出管理(更好地制作一个抽象的API以便于移植)

- 系统层(同步原语,进程间通信和

其他所有系统特定的 - 更好地为

便携性制作抽象API

- 通用数据结构管理(例如搜索,排序,列表,

树,哈希表等)

- 面向任务的数据处理(可以是任何东西,范围从文本

处理和转换为信号处理(音频,视频,无论如何),

数据压缩/加密,各种计算任务 - 每个不同的集合

的操作值得拥有自己的文件(或者几个文件的集合))

- 辅助/杂项/辅助函数的重要性很小,也许

频繁使用


我不确定你在谈论什么库,但将代码分成几个compilaion单元不能让它变得更大。实际上,它可以使它变得更小(如果你将可能根本不使用的代码放入一个单独的.c文件中 - 它的目标代码赢了''除非必要,否则必须链接。

每个库和目标文件只链接一次,除非你的工具被破坏或允许某种程度的滥用。


请注意,将代码分离成不同的单元,尽可能地更好地使用b / b
允许更简单的维护,测试和调试。这是做这件事的主要原因。并且不要忘记

重新编译一个巨大的.c文件需要的时间比

重新编译一个小文件。


Alex

PS请不要发帖。

A:是的,爱丽丝梦游仙境中的人首先要把蛋糕送到几个人的b $ b $ 。

问:真的吗?我不明白。你能给我一个例子吗?

答:因为它会使事件流动变得复杂

问:为什么顶级帖子不好?


Steffen Loringer < ST ************** @ freenet.de>在消息中写道

news:3q ************ @ news.dfncis.de ...
*.h should contain public info that''s intended for use by the caller, e.g.:
- macros
- type definitions
- inline functinos (you may need to declare them as "static inline" --
depends on the compiler I guess)
- externs
*.c should contain everything else that''s internal and not to be exposed to
the outer world.
This is as far as the .h vs .c goes.
But then you also should separate the code semantically, put in different .?
files the code for different things, e.g.:
- input/output management (better to make an abstract API for portability)
- system layer (synchronization primitives, interprocess communication and
everything else that''s system-specific -- better to make an abstract API for
portability)
- general purpose data structure management (e.g. searching, sorting, lists,
trees, hashtables, etc)
- task-oriented data processing (can be anything, ranging from text
processing and conversion to signal processing (audio, video, whatever),
data compression/encryption, various computation tasks -- every distinct set
of operations deserves its own file (or set of a few files))
- auxiliary/miscellaneous/helper functions of small importance and maybe
frequent use

I''m not sure what libraries you''re talking about, but separating the code
into several compilaion units must not make it any bigger. Actually, it can
make it smaller (if you put the code that may not be used at all into a
separate .c file -- its object code won''t be linked in unless necessary).
Each library and object file is linked only once unless your tools are
broken or allow some degree of misuse.

Mind you, separation of the code into distinct units, better as much
independednt as possible, allows for simpler maintainance, testing and
debugging. That''s the primary reason to do such a thing. And don''t forget
that recompilation of a single huge .c file will take longer than
recompilation of a small one.

Alex
P.S. please don''t top post.
A: Yep, Alice in the Wonderland had first to serve the cake out to a few
persons and only then cut it in parts.
Q: Really? I don''t get it. Could you give me an example?
A: Because it makes the flow of events complicated
Q: Why top posting is bad?

"Steffen Loringer" <st**************@freenet.de> wrote in message
news:3q************@news.dfncis.de...
没有真正的问题。但是可能存在良好编码的规则等......
我通过程序的功能部分分离我的功能。进入标题
* .h和source * .c文件。
我必须为每个* .h和* .c包含许多库,这是否会使我的
可执行文件更大? ?

感谢您的回复,Alexei!

Alexei A. Frounze schrieb:
There is no real problem. But there may be rules for good coding etc...
I separated my functions "by function part of the program" into header
*.h and source *.c files.
I have to include many libraries for each *.h and *.c, does this make my
executable bigger at the end??

Thanks for your reply, Alexei!

Alexei A. Frounze schrieb:
" Steffen Loringer" < ST ************** @ freenet.de>在留言中写道
新闻:3q ************ @ news.dfncis.de ...
"Steffen Loringer" <st**************@freenet.de> wrote in message
news:3q************@news.dfncis.de...
任何人都可以推荐一个好的wbeppage将程序模块化为不同的文件?
can anyone recommend a good wbeppage concerning modularisation of C
programs into different files?



但是问题是什么?通常,这是通过将代码中更多或
的独立部分分成单独的文件来完成的。只是。
课程中可能涉及相当多的编码,而不仅仅是复制''n''pasting ...
但就C而言,问题是什么?
Alex


But what is the problem? Normally this is done by separating more or less independent portions of the code into separate files. Just that. Of course that may involve quite some coding, not just copy''n''pasting...
But as far as C goes, what''s the problem?

Alex



这篇关于模块化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆