有什么方法有模块化C code吗? [英] What methods are there to modularize C code?

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

问题描述

什么方法,实践和惯例你知道的模块化C code作为一个项目的发展规模?

What methods, practices and conventions do you know of to modularize C code as a project grows in size?

推荐答案

创建其中只包含有什么必要使用一个模块的头文件。在相应的.c文件(S),做任何事情,并不意味着是可见的外部(辅助功能)静态的。使用一切外部可见的名称prefixes有助于避免命名空间冲突。 (如果一个模块跨越多个文件,事情变得更加困难,因为你可能需要公开内部的事情,不能掩盖它们与静态)

Create header files which contain ONLY what is necessary to use a module. In the corresponding .c file(s), make anything not meant to be visible outside (e.g. helper functions) static. Use prefixes on the names of everything externally visible to help avoid namespace collisions. (If a module spans multiple files, things become harder., as you may need to expose internal things and not be able hide them with "static")

(如果我尝试提高C,有一件事我会做的是使静态的函数的默认作用域。如果你想之外的东西看得见,你有出口或全球将其标记或者类似的东西。)

(If I were to try to improve C, one thing I would do is make "static" the default scoping of functions. If you wanted something visible outside, you'd have to mark it with "export" or "global" or something similar.)

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

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