Should I use #include in headers?

后端 未结 9 1362
甜味超标
甜味超标 2020-11-22 04:55

Is it necessary to #include some file, if inside a header (*.h), types defined in this file are used?

For instance, if I use GLib and wish to use the

9条回答
  •  星月不相逢
    2020-11-22 05:16

    A good practice is to only put #includes in an include file if the include file needs them. If the definitions in a given include file are only used in the .c file then include it only in the .c file.

    In your case, i would include it in the include file between the #ifdef/#endif.

    This will minimize dependencies so that files that don't need a given include won't have to be recompiled if the include file changes.

提交回复
热议问题