{"thread":{"id":"29199","subject":"header file at a top","startedAt":"2011-12-17T21:57:42Z","lastAt":"2011-12-18T05:43:52Z","messageCount":2,"participants":["Thiago Farina","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"181422","messageId":"CACnwZYdSPPhLyu6Oi3k2aNzYqvmD=xDYWvCEd2ofyJSntqKdJg@mail.gmail.com","threadId":"29199","inReplyTo":null,"subject":"header file at a top","fromName":"Thiago Farina","fromEmail":"tfransosi@gmail.com","sentAt":"2011-12-17T21:57:42Z","receivedAt":"2011-12-17T21:57:42Z","isPatch":false,"sender":{"key":"tfransosi@gmail.com","avatar":"https://avatars.githubusercontent.com/u/970071?v=4"},"body":"Hi folks,\n\nI don't understand why in git the .h file is not included as the first\nsubstantive line of the .c file.\n\ni.e:\n\nfoo.c\n--------------------------------------------------------------------\n#include \"foo.h\"\n\n/* in alphabetical order */\n#include \"bar.h\"\n#include \"tiz.h\"\n\nAny particular reason we include the corresponding header file at some\nrandom position in the source file?\n"},{"id":"181431","messageId":"20111218054352.GB4462@sigill.intra.peff.net","threadId":"29199","inReplyTo":"CACnwZYdSPPhLyu6Oi3k2aNzYqvmD=xDYWvCEd2ofyJSntqKdJg@mail.gmail.com","subject":"Re: header file at a top","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-12-18T05:43:52Z","receivedAt":"2011-12-18T05:43:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Dec 17, 2011 at 07:57:42PM -0200, Thiago Farina wrote:\n\n> I don't understand why in git the .h file is not included as the first\n> substantive line of the .c file.\n> \n> i.e:\n> \n> foo.c\n> --------------------------------------------------------------------\n> #include \"foo.h\"\n> \n> /* in alphabetical order */\n> #include \"bar.h\"\n> #include \"tiz.h\"\n> \n> Any particular reason we include the corresponding header file at some\n> random position in the source file?\n\nThe first include in any git source file should be either\n\"git-compat-util.h\", or something that includes it (usually \"cache.h\").\nThis introduces compatibility wrappers and definitions which may be used\nby other headers.\n\nAfter that, the next one could be \"foo.h\", and I do tend to like that\nstyle (since it gives a check that foo.h has no surprising header\ndependencies). But I think we simply don't bother caring about header\ndependencies in git (i.e., we do have recursive includes in some places,\nbut we don't require them, and in practice the compiler will tell us if\na source file fails to include a depended-upon header).\n\n-Peff\n"}]}