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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:50:45+00:00 2026-05-20T09:50:45+00:00

I’m working on an open-source project, and there is an hash_table that I need

  • 0

I’m working on an open-source project, and there is an hash_table
that I need to change for a more efficient hash_table, so, I’m trying
to use the header <search.h>;

The problem, is that I need to overwrite the functions that is already
being used all over the project … but for that, I need to use sizeof(struct hsearch_data)
but it doesn’t work.

Follow the code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define _GNU_SOURCE
#include <search.h>
#include "hashtable.h"

#define MAX_ELEMENTS 100
#define ERROR 2
#define SUCCESS 0

hash_table *new_hash_table()
{
    hash_table *table = (hash_table *) malloc(sizeof(struct hsearch_data));
    *table = {0};   

    int status = hcreate_r(MAX_ELEMENTS, table);

    if (status == 0) {
            hdestroy_r(table);
            return NULL;
    }

    return table; 
}

PS: in the header file, there is a
typedef struct hsearch_data hash_table;

I got the error message:

hashtable.c: In function ‘new_hash_table’:
hashtable.c:18: error: invalid application of ‘sizeof’ to incomplete type ‘struct hsearch_data’ 
hashtable.c:19: error: dereferencing pointer to incomplete type

Can anybody help me out?

  • 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-20T09:50:45+00:00Added an answer on May 20, 2026 at 9:50 am

    Apparently, the trouble is that the <search.h> header on your platform does not define the structure type. As noted in a comment to the question, on a RHEL5 Linux machine, the defines ‘struct hsearch_data‘ when __USE_GNU is defined, which is, in turn, defined when _GNU_SOURCE is defined as you have it. However, not all machines are Linux. I note that POSIX does define the <search.h> header, but does not specify the structure you are seeking to use.

    You will need to track down where the project defines the structure, and decide how you can make that available to this code. It may be simple – if the structure is safely segregated in a header which can be safely included. It may be complex if the header that defines the structure also defines other things which you can’t use.

    Since you are trying to preserve the same interface as the original code, you should be aiming to use the original header to provide the correct interface definition.

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

Sidebar

Related Questions

No related questions found

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.