问题描述
我是新来编程。学习C截至目前。据我所知,头文件只包含的声明和函数原型,而不是函数本身。我是不是正确的?
据我所知,图书馆是一个包含不同的对象codeS的单个文件。难道这些对象codeS不一定只写C语言或其他语言也可以用来产生这样的对象codeS?
在链接,并在整个库文件得到重视的可执行文件或只是对象codeS在头文件中声明?
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.
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.
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.
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.
这篇关于头文件和标准库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!