Author Topic: main.h a header file for the module containing main()  (Read 823 times)

0 Members and 1 Guest are viewing this topic.

Offline AlfBazTopic starter

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
main.h a header file for the module containing main()
« 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.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6239
  • Country: fi
    • My home page and email address
Re: main.h a header file for the module containing main()
« Reply #1 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?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11236
  • Country: us
    • Personal site
Re: main.h a header file for the module containing main()
« Reply #2 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?
Alex
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3713
  • Country: us
Re: main.h a header file for the module containing main()
« Reply #3 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf