peturdainn, (edited )
@peturdainn@mastodon.social avatar

small discussion here, resulting in this poll about C header dependencies:

if a header file depends on another header, do you include it before it in de source file, or do you include it in the header that depends on it?

Ive,

@peturdainn de resultaten zijn duidelijk, er is maar 1 goeie manier!

peturdainn,
@peturdainn@mastodon.social avatar

@Ive inderdaad... ik zal me moeten aanpassen

ives,
@ives@mstdn.social avatar

@peturdainn In the header file. But make sure you use include guards in your header files.
https://en.wikipedia.org/wiki/Include_guard

peturdainn,
@peturdainn@mastodon.social avatar

@ives yeah I know

and I agree with doing it in the header file for things that can be thought of a components.

For own code, I'm leaning towards putting it in source, because opening the c file shows me a list of other files that the code depends on.

And that's even more so when you get headers included in headers and again included in headers

ives,
@ives@mstdn.social avatar

@peturdainn I wouldn't do that. For complex projects, that list in the source file can get rather long. And what do you do if a header changes and no longer depends on another one? Do you edit all the files that include it to remove the include there as well? Sounds quite bothersome.

peturdainn,
@peturdainn@mastodon.social avatar

@ives I tend to group functionality in components or API's so changes in them have no effect, but yes sometimes the list gets long

OTOH the discussion started here because somebody had been doing something in a separate part of the code not quite by the (design) book and caused weirdness, and without the headers in headers I would never have seen their non-conforming constructs

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ethstaker
  • thenastyranch
  • GTA5RPClips
  • everett
  • Durango
  • rosin
  • InstantRegret
  • DreamBathrooms
  • magazineikmin
  • Youngstown
  • mdbf
  • slotface
  • cisconetworking
  • kavyap
  • JUstTest
  • normalnudes
  • modclub
  • cubers
  • ngwrru68w68
  • khanakhh
  • tacticalgear
  • tester
  • provamag3
  • Leos
  • osvaldo12
  • anitta
  • megavids
  • lostlight
  • All magazines