Re: Casting int'** to 'const int * const * const' dosn't work, why?
- From: Tor Rustad <tor_rustad@xxxxxxxxxxx>
- Date: Fri, 01 Jun 2007 23:57:01 +0200
Jonas.Holmsten@xxxxxxxxx wrote:
Hello
I'm porting some C++ stuff to C and having problem to get it through
gcc.
Here is a condensed version of the problem:
void foo(const int * const * const ptr)
{}
main()
{
int i = 5;
int *ptr = &i;
foo(&ptr);
}
The warning is:
warning: passing arg 1 of `foo' from incompatible pointer type.
Can't C implicit cast a int** to 'const int * const * const'? (it
works fine in C++)
This is really a question for Chris Torek...
Here is a simpler example:
$ cat const_cast.c
int main(void)
{
int **ppi;
const int * const *pcpci;
pcpci = ppi;
return 0;
}
$ cc -ansi -pedantic -Wall -W const_cast.c
const_cast.c: In function âmainâ:
const_cast.c:7: warning: assignment from incompatible pointer type
which requires a diagnostic in C (but perhaps not in C++, since no const'ness is lost).
In C, two types are compatible if they are the same type (not only if). A type qualifier (like const), change the type. When it comes to pointer types, they are compatible, if they point to compatible types.
--
Tor <torust [at] online [dot] no>
.
- Follow-Ups:
- Re: Casting int'** to 'const int * const * const' dosn't work, why?
- From: Ben Bacarisse
- Re: Casting int'** to 'const int * const * const' dosn't work, why?
- From: CBFalconer
- Re: Casting int'** to 'const int * const * const' dosn't work, why?
- References:
- Casting int'** to 'const int * const * const' dosn't work, why?
- From: Jonas . Holmsten
- Casting int'** to 'const int * const * const' dosn't work, why?
- Prev by Date: Re: Declaring static pointers.
- Next by Date: Re: assigning const char* to char*
- Previous by thread: Re: Casting int'** to 'const int * const * const' dosn't work, why?
- Next by thread: Re: Casting int'** to 'const int * const * const' dosn't work, why?
- Index(es):
Relevant Pages
|