【问题标题】:string.h header in the file with the function main带有函数 main 的文件中的 string.h 标头
【发布时间】:2017-09-13 20:28:42
【问题描述】:

我有一个包含多个 .c 和 .h 文件的程序。 在其中一个 .c 文件中,我使用了函数 strcmp()。我在这个文件中添加了 string.h 的标题

main函数的文件中的string.h头文件是否也需要?

谢谢!

【问题讨论】:

  • 一般来说,好的做法是在直接需要它们的文件中包含所有且仅包含标题。

标签: c header string.h


【解决方案1】:

如果包含函数 main 的翻译单元不使用函数 strcmp 或来自标头 <string.h> 的任何其他声明,则在此翻译单元中包含标头是多余的,只会使读者感到困惑。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-15
    • 2017-10-17
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多