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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:08:51+00:00 2026-05-23T20:08:51+00:00

I have a variable k of type const char * , and a function

  • 0

I have a variable k of type const char *, and a function in glib with the prototype

void g_hash_table_replace(GHashTable *hash_table,
                          gpointer key,
                          gpointer value);

gpointer is defined simply as

typedef void* gpointer;

I know that in this case it is, in fact, okay to pass in k as the key in g_hash_table_replace, however gcc gives me the error

service.c:49:3: warning: passing argument 2 of ‘g_hash_table_replace’ discards ‘const’ qualifier from pointer target type [enabled by default]
/usr/include/glib-2.0/glib/ghash.h:70:13: note: expected ‘gpointer’ but argument is of type ‘const char *’

this is with gcc 4.6.0. With 4.5.0 and earlier, a simple cast to (char *) sufficed to supress this warning, but gcc seems to have gotten ‘smarter’. I’ve tried (char *)(void *)k, but it still knows that the variable was originally const. What is the best way to silence this warning without calling strdup(3) on k?

  • 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-23T20:08:51+00:00Added an answer on May 23, 2026 at 8:08 pm

    I just tried this with gcc 4.6.1.

    #include <glib/ghash.h>
    #include <stdio.h>
    #include <unistd.h>
    
    const char *k="Testing";
    
    int main(int argc, char **argv)
    {
    
        int val = 1024;
    
        GHashTable *hash_table=NULL;
        g_hash_table_replace(hash_table,(gpointer) (intptr_t)k, &val);
    
        return 0;
    }
    

    Without casts, the error is as you describe above. But if I cast the const char* to intptr_t first as shown above, the warning is suppressed. Can you confirm that you still experience the error with my code sample?

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

Sidebar

Related Questions

I have a function whose prototype is as follows: void foo(const char * data);
I have a variable of type Hashmap <String,Integer >. In this, the Integer value
I have java class which has a variable of type char now I have
I have a templated function which I want to specialize foo to const char[N]
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda
I have a variable of type Dynamic and I know for sure one of
I have a variable of type Number, and i like to obtain the sign
Suppose I have a variable of type Int = 08, how can I convert
I have a reference-type variable that is readonly , because the reference never change,
I need your help, For example I have a decimal type variable and 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.