Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:18:31+00:00 2026-06-09T06:18:31+00:00

When I am creating a header file, that is going to be used by

  • 0

When I am creating a header file, that is going to be used by multiple developers, is it considered good programming practice to make that header file self-sufficient in terms of all the definitions and declarations used in it.

For example:

Header file 1 : types.h

#ifndef TYPES_H
#define TYPES_H
typedef unsigned int uint16
#endif

Header file 2: myheader.h

#ifndef MYHEADER_H
#define MYHEADER_H
uint16 myfunc(void);
#endif

I have used uint16 in myheader.h without including types.h . So if anyone wants to include myheader.h in their source file they should first include “types.h” and then include “myheader.h”. So this is actually forcing the developer to include header files in a specific order. I had always thought of this as bad practice, but I came across some code today at my company where to get a function declared in one file you need to include at least 4 other header files. So now I am confused, am I missing something, is there any place where this would be considered expected behaviour.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:18:33+00:00Added an answer on June 9, 2026 at 6:18 am

    Polluting the global namespace with unnecessary types is bad practice. The best you can do is provide forward-declarations where possible, and include other files where necessary. In your simplified case, you should include the header that defines uint16 in every header that uses it.

    If, for example, you can forward-declare the type, this is to be prefered. The rationale is that a forward-declaration is enough if you don’t actually use the type. And if you do use the type, you should include the header where it’s declared explicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on creating a header file that acts like the standard
I wanted to know what is the header file that is used for the
while I am creating a c++ header file, I declare the header file like;
I noticed that MIDL.exe only generates header file ( _h.h) and GUID file (
while creating a library that will be used on several projects, I encountered an
I have a file that I am creating on the fly like this: //
I'm creating a web service using gSoap, in the header file I have few
What do you think is best practice when creating public header files in C++?
I try to make a generic function in C++, that creating an array of
I have a header file, that is for a GNU Radio Signal Processing block,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.