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

  • Home
  • SEARCH
  • 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 8428503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:04:32+00:00 2026-06-10T05:04:32+00:00

I need to define a struct, let’s say //globalstruct.h typedef struct _GlobalStruct { int

  • 0

I need to define a struct, let’s say

//globalstruct.h
typedef struct _GlobalStruct {
    int a, b;
} GlobalStruct

and then use GlobalStruct wherever I want just by including globalstruct.h

For example:

//test.c
#include globalstruct.h
void test(GlobalStruct *gs){...}

How can I do this?

Regards

—-EDIT—-

I think I need to clarify a little bit more my question as I’m completely stuck.

//main.c
#include "gstruct.h"
#include "a.h"
#include "b.h"

...
void something(GlobalStruct *gs){...}

.

//gstruct.h
#ifdef gstruct_h
#define gstruct_h
typedef struct _GlobalStruct{
    int a, b;
} GlobalStruct;
#endif

.

//a.h
#ifdef a_h
#define a_h
#include "gstruct.h"
GlobalStruct a_something(...);
#endif

.

//a.c
#include "gstruct.h"
#include "a.h"
GlobalStruct a_something(...){...}

.

//b.h
#ifdef b_h
#define b_h
#include "gstruct.h"
GlobalStruct b_something(...);
#endif

.

//b.c
#include "gstruct.h"
#include "b.h"
GlobalStruct b_something(...){...}

.

Is this ok? Because if it is I’m missing something really silly/small/stupid.

BTW, I’m compiling with gcc main.c a.c b.c -o the_thing

—SECOND EDIT—-

I just created an online example so you can see it, download it and try it.
It’s ready-to-compile but it will fail at compilation time.

https://compilr.com/alexandernst/c-headers

  • 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-10T05:04:34+00:00Added an answer on June 10, 2026 at 5:04 am

    In the header files, #ifdef should be #ifndef

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

Sidebar

Related Questions

Say I need to use s : typedef struct tagSOMESTRUCT // Defined by someone
i need to help with structures, inheritance and definition. //define struct struct tStruct1{ int
I need to MPI_Gatherv() a number of int/string pairs. Let's say each pair looks
I need to define the constant in the module that use the method from
Let's suppose I have a struct like this: struct my_struct { int a; int
I need to define a matrix of int as a type. A column or
I have this struct: #define sbuffer 128 #define xbuffer 1024 typedef struct{ char name[sbuffer];
Suppose I define a struct in struct.h like so struct box { int value;
I need to define a template struct such that: element<T>::type is of type: T::element_type
I have defined a custom struct which I need to send over to another

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.