Похожие чаты

@Rmoog When we include a header file like math.h, it just

includes some function prototypes but doesn't include function definitions. And
after linking definitions are also included as machine code, right?
If we ourselves create a header files, should we provide both function prototypes and definitions in the header file, or should separate them into two header file and library file?

2 ответов

3 просмотра

Prototypes (declarations) are in headers. Definitions (implementations) are in library files. We don't have to include function implementations unless you have a static library and wish to statically link the function into your executable.

If you create own global functions and put the declaration into a header file, then you should define it in a .c file. If you define it in the header file and someone would include your header file in multiple .c files and then compile and link them, the linker would complain, that there are multiple definitions of your function. That's because an #include basically just copies the content of the header file into the .c file. There is an exception. You could put static function definitions into a header file. Static function have only file scope. They can't be used from different .c files. Thus, a linker wouldn't search for it in other .o files and also wouldnt complain that it finds more definitions of the function with that name.

Похожие вопросы

Обсуждают сегодня

Типа вызывать GetParent и проверять на соответствие GetModuleHandle?
The Bird of Hermes
67
Do any of you guys have interesting projects one could join? I'm a Middle Full-Stack developer (JS/TS, React & Node)
Lev Shapiro
40
$res = json_decode($наша строка из респонса); $res1 = array_map(fn($o) => $o->name, $res->breadcrumbs[0]->entities); Как такое будет на Хаскеле?.. В начале весь джейсон, в ко...
Хаскель Моисеевич Гопник
27
Hello, I have a question. Can anyone help me? I want to make my cryptocurrencies, like Tron, untraceable by anyone, even government organizations. I was told that to do this,...
 ➛ Eᒪᕼᗩᗰ
14
I read yesterday that in the near future most cryptos will be gone. It's like there is a lot of bullshit within the crypto sphere and this corruption some way is going to be c...
Kanah The Great
40
В чем сила брат, в NASM или FASM?
Isaac Kleiner
18
Вопрос по диагностике ошибок (я знаю в чем, в данном конкретном примере, я знаю, как исправить, пример модельный, понятно, что в реальности бывает намного запутаннее). module...
ⰄⰎⰋⰐⰐⰑⰛⰤⰧⰧⰩⰄ ⰊⰑⰁⰓⰡⰛⰦⰕⰫ
11
Хтось використовував Vapor на Windows?
Jaroshevskii
15
Hi Everybody I bought BCH when it’s 600 and I’m new in crypto what should I do ?
Khush
12
Тут кста кто-нибудь NeoVim использует?
Simple Sorcerer
13
Карта сайта