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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:00:37+00:00 2026-06-16T00:00:37+00:00

Possible Duplicate: why isnt it legal to convert (pointer to pointer to non-const) to

  • 0

Possible Duplicate:
why isnt it legal to convert (pointer to pointer to non-const) to a (pointer to pointer to a const)

Why do I get a warning (gcc 42.2) with the following call of foo?

void foo(const char **str)
{
  (*str)++;  
}

(...)
char **str;
foo(str);
(...)

I understand why we cannot call a function that excepting a char ** with a const char **, but the opposite seems ok to me, so why the following warning?

warning: passing argument 1 of 'foo' from incompatible pointer type
  • 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-16T00:00:38+00:00Added an answer on June 16, 2026 at 12:00 am

    It is wrong. There is no real room for arguing with the compiler here, since it’s supported by the spec. Here’s an example which explains exactly why it is wrong:

    void func(const char **p)
    {
        *p = "abc";
    }
    
    void func2(void)
    {
        char *a;
        func(&a);
        *a = 'x';
    }
    

    If the compiler didn’t spit out an error, your program would probably crash because you’d be overwriting a string literal (which is often marked read-only in memory).

    So you cannot implicitly cast char ** to const char ** because it would allow you to remove the const qualifier from any value — basically, it would allow you to ignore const at will without an explicit cast.

    The main reason the compiler gives a warning instead of an error is because lots of old code does not use the const qualifier where it would if the code were written today.

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

Sidebar

Related Questions

Possible Duplicate: why isnt it legal to convert (pointer to pointer to non-const) to
Possible Duplicate: What does void(U::*)(void) mean? Considering the following: template <class T> class myButtoncb
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Non-web SQL Injection Does someone know of a good example of a
Possible Duplicate: pow() isn’t defined void octal2decimal(char *octal, char *decimal) { int oct =
Possible Duplicate: How can a class have a member of its own type, isnt
Possible Duplicate: Difference between pointer to a reference and reference to a pointer Hi,
Possible Duplicate: Warning: mysql_query(): 3 is not a valid MySQL-Link resource I don't know
Possible Duplicate: Call to undefined method mysqli_stmt::get_result My web host has PHP 5.3.10 and

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.