I was revisiting my question How can I prevent header hell?, when I noticed a comment which said
A good technique for ensuring a header is independent is having a rule that the source file always includes its own header first. This will catch cases where you need to move dependency includes out of the implementation file into the header file
I am not sure that I follow that, and the reverse seems to have been the rule everywhere that I have worked. I never thought about it, or questioned it.
Are there any technical reasons for a .C or .CPP file to #include its own header file either for or last, or does it make no difference?
I am looking for technical reasons, not opinions. Nothing with “best”, which would be opinion. Answers which might help to prevent problems when refactoring or adding/removing other #includes are welcome.