头文件和标准库 [英] header file and standard library

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

问题描述

我是新来编程。学习C截至目前。据我所知,头文件只包含的声明和函数原型,而不是函数本身。我是不是正确的?

据我所知,图书馆是一个包含不同的对象codeS的单个文件。难道这些对象codeS不一定只写C语言或其他语言也可以用来产生这样的对象codeS?

在链接,并在整个库文件得到重视的可执行文件或只是对象codeS在头文件中声明?


解决方案

  

据我所知,头文件只
  包含声明和函数
  原型,而不是功能
  他们自己。


一般情况下,是的(虽然理论上可以把任何code你在头文件中想要的)。请记住,一个头文件通常只是的#include -d到一个源文件和的#include 基本上等同于复制和粘贴。


  

据我所知,图书馆是一个单一的文件


不一定。 库是有点宽松的名词,但一般来讲,​​它用来描述的功能(和潜在的数据)一起执行任务的一些有用的集合的集合。这些功能可在一个或多个源文件中定义。通常情况下,一个库是$ P $对 - 编译成一个独立的对象文件。但同样,不一定。


  

难道这些对象codeS一定只用C语言编写的


没有。它们可以用任何语言编写(因为它总是会被编译至原机code)所示。但是,如果你想的使用的从C库,那么一定兼容性要求必须满足,以确保C编译器知道如何正确地调用库函数。


  

在链接,并在整个库文件得到重视可执行


有时。这是什么作为的静态链接的。其他主要类型的动态链接的,其中库对象code表示的运行时的链接。

I am new to programming. learning C as of now. I understand that header file only contains the declarations and function prototypes, not the functions themselves. Am I correct?

I understand that Library is a single file that contains different object codes. Are these object codes necessarily written only in C language or other languages can also be used to generate such object codes?

On linking, does the entire library file get attached to the executable or just the object codes declared in the header file?

解决方案

I understand that header file only contains the declarations and function prototypes, not the functions themselves.

Usually, yes (although you can theoretically put any code you want in a header file). Remember that a header file is usually just #include-d into a source file, and #include is basically equivalent to a copy-and-paste.

I understand that Library is a single file

Not necessarily. "Library" is a bit of a loose term, but generally speaking, it's used to describe a collection of functions (and potentially data) that together perform some useful set of tasks. These functions may be defined in one or several source files. Typically, a library is pre-compiled into a standalone object file. But again, not necessarily.

Are these object codes necessarily written only in C language

No. They can be written in any language (because it will always be compiled down to raw machine code). But if you want to use the library from C, then certain compatibility requirements must be fulfilled, to ensure that the C compiler knows how to call the library functions correctly.

On linking, does the entire library file get attached to the executable

Sometimes. This is what's known as static linking. The other main type is dynamic linking, where the library object code is linked at run-time.

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

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