Похожие чаты

@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 ответов

9 просмотров

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.

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта