Click here to Skip to main content
15,867,453 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Where do you place your #includes? Pin
mo149229-Jan-19 2:27
mo149229-Jan-19 2:27 
GeneralRe: Where do you place your #includes? Pin
den2k8829-Jan-19 21:10
professionalden2k8829-Jan-19 21:10 
GeneralRe: Where do you place your #includes? Pin
Klaus-Werner Konrad24-Apr-19 4:31
Klaus-Werner Konrad24-Apr-19 4:31 
AnswerRe: Where do you place your #includes? Pin
CPallini29-Jan-19 10:49
mveCPallini29-Jan-19 10:49 
GeneralRe: Where do you place your #includes? Pin
den2k8829-Jan-19 21:07
professionalden2k8829-Jan-19 21:07 
GeneralRe: Where do you place your #includes? Pin
CPallini29-Jan-19 22:07
mveCPallini29-Jan-19 22:07 
AnswerRe: Where do you place your #includes? Pin
Stefan_Lang29-Jan-19 22:28
Stefan_Lang29-Jan-19 22:28 
AnswerRe: Where do you place your #includes? Pin
leon de boer30-Jan-19 2:26
leon de boer30-Jan-19 2:26 
I am going to disagree with almost all above in C the standard industry practice is the only time a header is declared in the header file is if an actual interface call requires a type in the header. There simply is no other valid reason you should ever do it because of caching blah blah blah others mentioned.

The basic premise is why would you want a dependency on the interface at compile time if the interface doesn't need to know the dependency. The header is there as clean interface segmentation layer not somewhere for you to play around with speed ups and your own personal playground.

Internally in the C file if your C code requires the header declare it in the .c file again because it is required!!!!!!

Basic rule you never include anything in any file that is not absolutely required .... that is the end of the story.

I am anal and actually record why I am including the unit with a comment... so this is a typical example
#include <stdbool.h>	// C standard unit needed for bool and true/false
#include <stdint.h>	// C standard unit needed for uint8_t, uint32_t, etc
#include <stdarg.h>	// C standard unit needed for variadic type and functions
#include <string.h>	// C standard unit needed for strlen

So on your example I would never declare windows.h in my unit header unless I had a function in the C file that needed the interface to pass a windows type again I would comment why the header is included and as an example
#include <windows.h>	// Windows standard header needed for HWND on calls

void MyUnitFunction (HWND window);

If I had the situation no public interface needed internal windows types (they were just using normal c types etc) the #include <windows.h> would only ever be in the .C file and not the header file as I don't need to tell the interface.

So for me no includes don't always go in the header files or in the C files they go where they are absolutely required !!!!!!!

You should find that alone will stop lots of stupid circular problems you would get otherwise. If you have two units that go circular and you really can't organize them better then as already mentioned above in one unit forward declare the other units interface functions. Generally you choose the one with the least functions to forward.
In vino veritas


modified 30-Jan-19 9:35am.

QuestionPf Pin
Member 1412898028-Jan-19 8:25
Member 1412898028-Jan-19 8:25 
AnswerRe: Pf Pin
CPallini28-Jan-19 9:20
mveCPallini28-Jan-19 9:20 
QuestionWin API or other? Pin
chipp_zanuff26-Jan-19 5:12
chipp_zanuff26-Jan-19 5:12 
AnswerRe: Win API or other? Pin
Victor Nijegorodov26-Jan-19 5:33
Victor Nijegorodov26-Jan-19 5:33 
AnswerRe: Win API or other? Pin
Joe Woodbury28-Jan-19 12:37
professionalJoe Woodbury28-Jan-19 12:37 
AnswerRe: Win API or other? Pin
leon de boer28-Jan-19 17:07
leon de boer28-Jan-19 17:07 
Questionc++ MS Word Pin
Member 1238494426-Jan-19 5:03
Member 1238494426-Jan-19 5:03 
AnswerRe: c++ MS Word Pin
jeron126-Jan-19 6:30
jeron126-Jan-19 6:30 
GeneralRe: c++ MS Word Pin
Member 1238494428-Jan-19 2:48
Member 1238494428-Jan-19 2:48 
AnswerRe: c++ MS Word Pin
Stefan_Lang28-Jan-19 2:11
Stefan_Lang28-Jan-19 2:11 
QuestionHow to print all source code what was running? Pin
Member 1308136924-Jan-19 16:35
Member 1308136924-Jan-19 16:35 
AnswerRe: How to print all source code what was running? Pin
Victor Nijegorodov24-Jan-19 20:49
Victor Nijegorodov24-Jan-19 20:49 
GeneralRe: How to print all source code what was running? Pin
Member 1308136924-Jan-19 21:54
Member 1308136924-Jan-19 21:54 
GeneralRe: How to print all source code what was running? Pin
HS_C_Student26-Jan-19 4:06
HS_C_Student26-Jan-19 4:06 
GeneralRe: How to print all source code what was running? Pin
Member 1308136926-Jan-19 11:22
Member 1308136926-Jan-19 11:22 
AnswerRe: How to print all source code what was running? Pin
Richard MacCutchan24-Jan-19 22:12
mveRichard MacCutchan24-Jan-19 22:12 
GeneralRe: How to print all source code what was running? Pin
Member 1308136925-Jan-19 4:24
Member 1308136925-Jan-19 4:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.