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 8806093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:02:13+00:00 2026-06-14T02:02:13+00:00

I’m working on a larger project than I’m used to, and I’m doing my

  • 0

I’m working on a larger project than I’m used to, and I’m doing my best to keep my code properly structured. I am programming a microcontroller and have some global variables, which as per some advice I read on here are all defined in a “global_variables.h” file which is included anywhere that the global variables are used.

I also put the typedef for the global variables into the “global_variables.h” file.

The problem I am running across is that the file1.c in which I use the global variable has a function1(new_type_t variable) which accepts the new typedef as a parameter. The problem with this is that I have the function1 prototype defined in the header (file1.h), but since the #include “global_variables.h” is located in file1.c, the function prototype in file1.h does not see the typedef.

I feel like this is a common occurrence, but Googling didn’t seem to provide too much help. Should I make a separate “global_variables.h” and “global_variables_types.h” and include the .h file in the headers of my other files and the .c in the sources?

  • 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-14T02:02:14+00:00Added an answer on June 14, 2026 at 2:02 am

    I don’t think that having a header file global_variables.h is sensible.

    If your project is a small single-person project (e.g. less than 50KLOC = 50 thousand lines of source code), and you don’t intend to make a reusable library, having one single header file for all the project is probably sensible. That header file would declare the global variables, and before them the relevant types. You’ll also declare all your functions, and at last define all your inlined functions. You could consider having the inlined functions in a separate header file (including from your main header).

    If you intend to make reusable code, make separate headers for separate subsystems of your project. But I don’t feel the need to have a header for just all the global variables.

    Most importantly, keep your set of global variables minimal. You should be able to count global variables with the fingers of a single hand. If you need more than 4 or 5 global variables, consider packing related global variables in a global struct. For instance, if the screen size is in global data, don’t declare int screen_width, screen_height; but rather

     struct {
        int width;
        int height;
     } screen;
    

    Of course, the true thing depends upon the project, and perhaps upon the build chain. Some proprietary compilers don’t really optimize, and might produce bad code if using global structures. If you use a recent GCC (as a cross compiler, preferably on Linux), you don’t have that issue, since GCC optimize well. Always enable all warnings on your compiler (e.g. build with gcc -Wall -g -O2)

    A good advice would be to study the source code of some existing free software similar to yours.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I

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.