EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: AlfBaz on February 28, 2021, 11:25:47 am

Title: main.h a header file for the module containing main()
Post by: AlfBaz on February 28, 2021, 11:25:47 am
Is any body else annoyed by the use of main.h or at least the name of it or have I missed some major paradigm shift.
Title: Re: main.h a header file for the module containing main()
Post by: Nominal Animal on February 28, 2021, 06:57:49 pm
Where have you encountered main.h?

Perhaps it is a mis-named config.h, containing compile-time configuration; perhaps auto-generated, or includes the auto-generated snippets?
Title: Re: main.h a header file for the module containing main()
Post by: ataradov on February 28, 2021, 06:59:08 pm
What is so annoying about it? Especially is the corresponding file is main.c.

main file may contain other things, not just main(). Where would you put those declarations if they need to be public?
Title: Re: main.h a header file for the module containing main()
Post by: ejeffrey on March 02, 2021, 06:20:14 pm
This is totally reasonable.  main.c is a reasonable place to define any global variables you have. If they need extern declarations main.h would be the place to put them.  I would give second thought to defining any functions in main.c that need to be declared elsewhere, but that is not a hard no, just something I would carefully consider.  main itself should not have a prototype, so if someone is using main.h to provide that it is a definite error.

I do agree that compile time constants settings are usually better off in something called config.h than main.h.