Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Im splitting up a program into multiple source files for the first time, and Im wondering what to put in .c files and what to put in .h files. (What does “.h\ mean, anyway?

0
Posted

Im splitting up a program into multiple source files for the first time, and Im wondering what to put in .c files and what to put in .h files. (What does “.h\ mean, anyway?

0

As a general rule, you should put these things in header (.h) files: macro definitions (preprocessor #defines) structure, union, and enumeration declarations typedef declarations external function declarations (see also question 1.11) global variable declarations It’s especially important to put a declaration or definition in a header file when it will be shared between several other files. Don’t repeat a declaration or macro definition at the top of two or more source files; do put it in a header file and #include it wherever needed. The reason is not just to save typing: you want to set things up so that whenever a declaration or definition changes, you only have to change it in one place, with the update propagated to all source files consistently. (In particular, never put external function prototypes in .c files. See also question 1.7.) On the other hand, when a definition or declaration should remain private to one .c file, it’s fine to leave it there. (Private file-scope functio

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123