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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:32:19+00:00 2026-06-15T04:32:19+00:00

During compilation of a call to the following function: char* process_array_of_strings(const char** strings); GCC

  • 0

During compilation of a call to the following function:

char* process_array_of_strings(const char** strings);

GCC complains when a char** is passed as argument:

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

While the function does not alter the characters (hence the const) it does duplicate the array of pointers in order to modify the character pointers themselves, so constant pointers are definitely undesirable here.

Compilation succeeds and the program appears to work. So how is the programmer supposed to handle this warning?

  • 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-15T04:32:20+00:00Added an answer on June 15, 2026 at 4:32 am

    This is why char ** is not automatically converted to const char ** in C++, and why the C compiler issues a warning while allowing it.

    /* This function returns a pointer to a string through its output parameter: */
    void get_some_string(const char ** p) {
        /* I can do this because p is const char **, so the string won't be modified. */
        *p = "unchangeable string in program core";
    }
    
    void f() {
        char * str;
        /* First, I'll call this function to obtain a pointer to a string: */
        get_some_string(&str);
        /* Now, modify the string: */
        for (char * p = str; *p; p++)
            *p = toupper(*p);
        /* We have just overwritten a constant string in program core (or crashed). */
    }
    

    From your description of what process_array_of_strings() does, it could just as well take const char * const * because it modifies neither the pointers nor the characters (but duplicates the pointers elsewhere). In that case, the above scenario would not be possible, and compiler theoretically could allow you to convert char ** to const char * const * automatically without warnings, but that’s not how the language is defined.

    So the answer is obviously that you need a cast (explicit). I’ve written up this expanation so that you can fully understand why the warning appears, which is important when you decide to silence one.

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

Sidebar

Related Questions

The following snippet produces an ambigious call to foo error during compilation, and I'd
Is there an environment variable for GCC/G++ to look for .h files during compilation?
GHC 7.0.3 (ubuntu repoes) produces during compilation warnings of kind SpecConstr Function `$j_se6a{v} [lid]'
During compilation process many errors are thrown on the screen. To start resolving them
I'm getting the error fatal error C9999: *** exception during compilation *** Whenever I
Out of nowhere, all of my stylesheets started throwing errors during compilation. lessc static/css/styles.less
Here's the error I get: Description: An error occurred during the compilation of a
With C++, I struggle to understand one compilation error. I have this function, with
What is the semantics of Bcast when number of processes during this call is
Quasi-quotes allow generating AST code during compilations, but it inserts generated code at the

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.