每个源文件头 [英] Header per source file

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

问题描述

我想了解每个背后每一个源文件的方法一个头的目的。在我看来,头被用于共享函数声明,的typedef 的和宏观的,利用他们几个文件之间。当你为一个头文件的 .C 文件,它有,每次你想看到一个函数声明或宏,你需要参考的头文件的缺点,并通常它更简单,一切都在一个源文件(不是整个软件,当然)。

I'm trying to understand the purpose behind one header per each source file method. As I see it, headers are meant for sharing function declarations, typedef's and macro's between several files that utilize them. When you make a header file for your .c file it has the disadvantage that each time you want to see a function declaration or macro you need to refer to the header file, and generally it is simpler that everything is in one source file (not the whole software, of course).

那么,为什么程序员使用这种方法吗?

So why do programmers use this method?

推荐答案

在C分离声明的头文件(必须是可用于使用函数的每个.c文件)来自定义(必须是在同一个地方) 。此外,他们提供了一个小模块,因为你可以把只有公共接口到一个头文件中,并没有提及功能和静态变量,应该是内部的.c文件。使用文件系统,提供一个公共接口和私有实现。

The header files in C separate declarations (which must be available to each .c file that uses the functions) from the definitions (which must be in one place). Further, they provide a little modularity, since you can put only the public interface into a header file, and not mention functions and static variables that should be internal to the .c file. That uses the file system to provide a public interface and private implementation.

一个.h文件中的一个.c文件的做法主要是方便。这样,你知道,声明是在.h文件,并在相应的.c文件中的定义。

The practice of one .h file to one .c file is mostly convenience. That way, you know that the declarations are in the .h file, and the definitions in the corresponding .c file.

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

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