R
Roger Leigh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
A lot of functions use const pointer arguments. If I have a non-const
pointer, it is transparently made const when I pass it to the
function, e.g. char * -> const char *. However, this does not appear
to work when I add another level of indirection:
void test1 (char **value)
{}
void test2 (const char **value)
{}
void test3 (const char * const *value)
{}
void test4 (char * const *value)
{}
int
main (void)
{
char **v;
test1(v);
test2(v);
test3(v);
test4(v);
return 0;
}
$ gcc -Wall -pedantic -o test1 test.c
test.c: In function ‘main’:
test.c:19: warning: passing argument 1 of ‘test2’ from
incompatible
pointer type
test.c:20: warning: passing argument 1 of ‘test3’ from
incompatible pointer type
Why is this sort of conversion requiring an explicit cast? Adding
(const char * const *) casts all over the place doesn't really improve
code readability, even if it does give me const correctness!
Thanks,
Roger
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iD8DBQFCzGCVVcFcaSW/uEgRArUGAKDoU72gbXjcIj+vTl3p6G1HD0B5lACgvwxV
ih47/4KIkBWTCY8lVM5nndk=
=v5Ep
-----END PGP SIGNATURE-----
Hash: SHA1
A lot of functions use const pointer arguments. If I have a non-const
pointer, it is transparently made const when I pass it to the
function, e.g. char * -> const char *. However, this does not appear
to work when I add another level of indirection:
void test1 (char **value)
{}
void test2 (const char **value)
{}
void test3 (const char * const *value)
{}
void test4 (char * const *value)
{}
int
main (void)
{
char **v;
test1(v);
test2(v);
test3(v);
test4(v);
return 0;
}
$ gcc -Wall -pedantic -o test1 test.c
test.c: In function ‘main’:
test.c:19: warning: passing argument 1 of ‘test2’ from
incompatible
pointer type
test.c:20: warning: passing argument 1 of ‘test3’ from
incompatible pointer type
Why is this sort of conversion requiring an explicit cast? Adding
(const char * const *) casts all over the place doesn't really improve
code readability, even if it does give me const correctness!
Thanks,
Roger
- --
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iD8DBQFCzGCVVcFcaSW/uEgRArUGAKDoU72gbXjcIj+vTl3p6G1HD0B5lACgvwxV
ih47/4KIkBWTCY8lVM5nndk=
=v5Ep
-----END PGP SIGNATURE-----