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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:31:54+00:00 2026-06-18T06:31:54+00:00

I’ve been getting this warning: note: expected ‘const char **’ but argument is of

  • 0

I’ve been getting this warning:

note: expected ‘const char **’ but argument is of type ‘char **’

For now, I’m passing the arguments by casting them to const char **. Is there any other way I can get rid of it?

  • 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-18T06:31:55+00:00Added an answer on June 18, 2026 at 6:31 am

    Short Answer

    Can you safely typecast char ** to const char**? No. (Not safely anyway), and the reason is far more subtle than you may think. Can you get rid of it another way? Sure. Load an array of const char* values from your char* values and pass that instead. (or change the callee prototype, but thats cheating =P).

    Consider the following code, which essentially does everything you’re wishing except invoke a function. The marked line demonstrates the equivalent point-of-cast

    const char *s = "Test";
    char *p = NULL;
    char **pp = &p;             // Put address of our pointer in our pointer-to-pointer.
    const char **cpp = pp;      // Here: assigning  char** to const char**
    *cpp = s;                   // perfectly legal; pp and s both finish "char const"
    *p = 0;                     // ru ro raggy
    

    It takes awhile to really stare at this, and admittedly I didn’t see it at first either. @sheu did a solid job of catching it about 24 hours before I really thought about it long enough to realize he was right all along (and I actually upvoted that answer before writing this one). Then I thought he was wrong about the same time he thought his answer wasn’t applicable. Turns out we were both wrong on that leap, because he was right the first time, I was wrong the second time, and now… ugh.

    On VS2012 and VS2010 both the marked line will flag an error without a cast. clang will compile it with a warning in C, but allow it (which I found surprising). Given, you do have to really step out of your happy place to break it, but it is still none-the-less broken.

    The rest of this is a diatribe on identifying pointer types, their constness, and what is equivalent to what.


    Long Diatribe on Pointers And Const

    The warning is because char ** and const char ** are not equivalent (duh). To be correct, you could fix the prototype (callee), or fix the caller (by loading an array of const char * and passing that). But can you safely typecast the first to the second? Hmmm….

    Remember, by the standard const goes to the item immediately to its left. Declaring it on the most-left of a data type is a nicety that the language supports, but often introduces confusion or problems. As a rule-of-thumb, if const appears on the far-left of a decl immediately before the type, it applies to the data type; not the subsequent pointer (if any). When it appears to the right of anything it applies to the immediate-left decl-part, be it a data type part or a pointer part, but no matter what it only applies to a single part.

    A plethora of samples follows:

    No Indirection:

    const char ch;    // const character. must be initialized.
    char const ch;    // same as above
    

    Single-Indirection:

    char *p;               // p is mutable, *p is mutable
    const char *p;         // p is mutable, *p is const
    char const *p;         // same as above.
    char *const p;         // p is const, *p is mutable, must be initialized.
    char const *const p;   // p is const, *p is const, must be initialized.
    

    Double Indirection:

    char **p;        // ptr-to-ptr-to-char
                     // p, *p, and **p are ALL mutable
    
    const char **p;  // ptr-to-ptr-to-const-char
                     // p and *p are mutable, **p is const
    
    char const **p;  // same as above
    
    char *const *p;  // ptr-to-const-ptr-to-char
                     // p is mutable, *p is const, **p is mutable.
    
    char **const p;  // const-ptr-to-ptr-to-char
                     // p is const, *p is mutable, **p is mutable.
                     // must be initialized.
    
    const char **const p;  // const-ptr-to-ptr-to-const-char
                           // p is const, *p is mutable, **p is const.
                           // must be initialized.
    
    char const **const p;  // same as above
    
    char const *const *p;  // ptr-to-const-ptr-to-const-char
                           // p is mutable, *p is const, **p is const.
    
    const char *const *p;  // same as above.
    
    char *const *const p;  // const-ptr-to-const-ptr-to-char
                           // p is const, *p is const, **p is mutable.
                           // must be initialized.
    

    And of course who can leave home without…

    char const *const *const p;   // const-ptr-to-const-ptr-to-const-char
                                  // everything is const.
                                  // must be initialized.
    
    const char *const *const p;   // same as above
    

    So how does this affect your question? When compiling that code in C, without a cast you’ll get a compiler warning (or error if compiling with -Werror). When compiling in C++, you’ll just plain error because the parameter signature doesn’t match. But why?

    Because these have no direct equivalence:

    const char **p;  // ptr-to-ptr-to-const-char
                     // p and *p are mutable **p is const
    
    char **p;        // ptr-to-ptr-to-char
                     // p, *p, and **p are all mutable
    

    When compiling with clang, the exact warning in C is given as:

    main.c:15:9: Passing char ** to parameter of type const char ** discards qualifiers in nested pointer types.

    VS2010 and VS2012 both, on the other hand, toss an error:

    error C2440: ‘initializing’ : cannot convert from ‘char **’ to ‘const char **’

    It seems odd, but VS is actually more correct (wonders never cease).

    And that makes perfect sense. Nestled down in the type declaration is the fact that the first of these does not allow modification to the final data, the second does. From above we know that char ** and const char ** (aka. char const **), are not the same. At the bottom of one is a pointer to a const char, while the other has a pointer to char.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.