Bug 37937 - passing (char **) to function expecting (const char * const *)
Summary: passing (char **) to function expecting (const char * const *)
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 6.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-04-26 22:59 UTC by Need Real Name
Modified: 2007-04-18 16:32 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-04-26 22:59:16 UTC
Embargoed:


Attachments (Terms of Use)

Description Need Real Name 2001-04-26 22:59:12 UTC
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 19:06:17 UTC
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.