This service will be undergoing maintenance at 20:00 UTC, 2017-04-03. It is expected to last about 30 minutes
Bug 37937 - passing (char **) to function expecting (const char * const *)
passing (char **) to function expecting (const char * const *)
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
6.2
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-04-26 18:59 EDT by Need Real Name
Modified: 2007-04-18 12:32 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-04-26 18:59:16 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2001-04-26 18:59:12 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.6C-CCK-MCD EMS-1.4 [en] (X11; U; SunOS 5.6 sun4m)


gcc gives a warning "incompatible pointer type" when passing a char **
to a function where the argument is of type "const char * const *".
gcc will allow the top level to become const without complaint (that is,
passing (const char **) is perfectly acceptable).  It seems that gcc should
scan down through the type and allow const to be added at all levels during
argument passing.

Reproducible: Always
Steps to Reproduce:
1.Compile the following program:
const char f(const char * const * p) {
        return **p;
}

void g(void) {
char *v = "testing";
char **q = &v;

        f( q );                 /* gives error */
        f( (const char **)q );  /* OK */
}


Actual Results:  gcc version 2.95.2 19991024 (release) gives:
x.c:9: warning: passing arg 1 of 'f' from incompatible pointer type


Expected Results:  clean compile
Comment 1 Jakub Jelinek 2001-04-27 15:06:17 EDT
No, gcc is correct on this. A pointer to 'const char *' is incompatible
with pointer to 'char *', see ISO C standard, chapter 6.7.3.

Note You need to log in before you can comment on or make changes to this bug.