[QUOTE="Jens Schweikhardt"]\nconsider a small project of 100 C source and 100 header files.\nThe coding rules require that only C files include headers,\nheaders are not allowed to include other headers (not sure if\nthis is 100% the "IWYU - Include What You Use" paradigma).\n\nThe headers contain only what headers should contain:\nprototypes, typedefs, declarations, macro definitions.\n\nThe problem: given a set of headers, determine a sequence of\n#include directives that avoids syntax errors due to undeclared\nidentifiers. I.e. if "foo.h" declares type foo_t and "bar.h" uses\nfoo_t in a prototype, "bar.h" must be included before "foo.h".[/QUOTE]\n\nI have been reading the many comments in this thread with some\ninterest. Reading through your responses, I have come up with\nthis summary of motivations for using this approach (these are\nmy paraphrasings, often not quotes of the originals):\n\n+ no lint warnings about repeated headers\n+ no need for include guards\n+ doxygen dependency graph much simpler\n+ no cycles in include graph\n+ removing unneeded includes is easier\n+ simpler compiler diagnostics\n+ easier to generate dependency makefile\n+ improved identifiability of refactoring opportunities\n+ ... and of interface accumulation [not sure what this means]\n+ ... and of code collecting fat\n+ constant reminders of all dependencies of each .c file\n\nSome questions:\n\n1. Is this an accurate summary?\n\n2. Has anything been left out (ie, is there any other\npositive you would add to the list)?\n\n3. Would you mind listing these from most important\nto least important, and giving some indication of\nrelative weight for each item?\n[QUOTE]\nI'm not a computer scientist, but it sounds as if this requires a\ntopological sort of all the '"foo.h" needs "bar.h"' relations.\nNow the interesting part is: how to automate this, i.e. how to\ndetermine "this header declares identifiers A, B, C and requires\nX, Y, Z"? [IWYU by google was looked at but seems not a good\nsolution][/QUOTE]\n\nYes, a topological sort. The topological sort is the easy\npart - the harder part is identifying what the first-level\ndependencies are.\n[QUOTE]\nCan you think of a lightweight way to solve this? Maybe using\nperl, the unix tool box, make, gmake, gcc, a C lexer?[/QUOTE]\n\nI may have some suggestions here, but first I would like to read\nthrough responses to the questions asked above, to make sure I'm\ngoing in a good direction.