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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:47:27+00:00 2026-05-27T15:47:27+00:00

I have a strange problem in C about including header files. main.c #include <stdio.h>

  • 0

I have a strange problem in C about including header files.

main.c

#include <stdio.h>
#include <stdlib.h>
#include "location.h"

int waste_new_line();

int main()
{
    location *crossroads = malloc(sizeof(*crossroads));
...

location.h

typedef struct Location_Struct location;

location.c

typedef struct Location_Struct {
    int ID;
    char *name;
    char *description;
} location;

int setup_location(location* l, char* name)
{
    ...

Now this isn’t working because

location *crossroads = malloc(sizeof(*crossroads));

is throwing an error:dereferencing pointer to incomplete type meaning that it can see the contents of location.h, yet it doesn’t seem to be aware of location.c…

I’ve looked around and all the tutorials I’ve seen say that the linker will link both files together.

EDIT:

I have altered the code to include an initializer inside location.c as so:

main.c

...
#include "location.h"

int waste_new_line();

int main()
{

    location *crossroads = initialize_location();
    ....

location.h

typedef struct Location_Struct location;

location* initialize_location();

location.c

...
typedef struct Location_Struct {
    int ID;
    char *name;
    char *description;
} location;

location* initialize_location(location* l)
{
    return malloc(sizeof(location));
}
...

This is still throwing the same error, yet only when I try and access the members of crossroads using:

crossroads->description

this will throw the deferencing to incomplete type error.

EDIT 2: For now I’ve decided to just put the struct definition in the header file…

  • 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-05-27T15:47:27+00:00Added an answer on May 27, 2026 at 3:47 pm

    This behaviour is expected. When you #include "location.h", only the header file is visible to the compiler. The location.c file comes along later, at link time.

    You have two options:

    1. Add a function, which you declare in location.h and define in location.c, which does the necessary malloc and returns a pointer.
    2. Move the full definition of the struct to the header file.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a strange problem about in_array recently which I cannot understand. e.g.
I have a strange problem that is only happening in a single location. I
I have a strange problem that I don't understand about DataPager. After changing the
I have a strange problem where the users of my application complain about the
I'm having a strange problem - I have about 14.5 million bitmap images, that
I have a strange problem on a website I developed ( http://misenplacecatering.it/location ). The
I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed
i have strange problem doing reporting: i have numerous clients with different issued invoices.
We have very strange problem, one of our applications is continually querying server by
I have a strange problem with mod_rewrite, the rules that are relevant here are:

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.