Jump to content

Recommended Posts



I am a bit confuse when to use .h and .c but I definitely sported the differences when using two different files.


When I use .h, in the code I do not need to add #include <system> and the compiler build the project very quickly.


but when I use .c, I need to add #include <system> and the compiler seems to build the project slower because it needs to compile each .c files.


Because I want my main .c code readable in a complex system therefore I decided to spread each small functions or routine into difference files.


At the moment, I use .h only for the MCU's configuration words and global variable declaration and functions with or without "inline" are written in .c file.

I find it very annoying is, the compiler take very long time to build the project when there are more than three .c files.



So can anyone tell me when should I use .h and .c?



Thank you in advance!!!!!!

Link to post
Share on other sites
...So can anyone tell me when should I use .h and .c?...


Anything that can be shared between several source files goes to .h These are usually defines, typedefs and struct/union/class definitions. Everything else goes to .c files.




Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...