[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH]simple(for me only? not sure) typecasting

From: Philip Martin <philip_at_codematters.co.uk>
Date: 2006-10-13 18:45:17 CEST

Kamesh Jayachandran <kamesh@collab.net> writes:

> Daniel Rall wrote:
>> On Thu, 12 Oct 2006, Kamesh Jayachandran wrote:
>>>
>>> <snip>
>>> svn_sort_compare_paths(const void *a, const void *b)
>>> {
>>> const char *item1 = *((const char * const *) a);
>>> const char *item2 = *((const char * const *) b);
>>> return svn_path_compare_paths(item1, item2);
>>> }
>>> </snip>
>>> I feel it is easier to understand 'const char *item1 = *((const
>>> char **) a);' than 'const char *item1 = *((const char * const *)
>>> a);'.
>>
>> This patch changes the semantics of those statements.
>>
> Agreed. Can someone point me to the docs where I can understand the
> typecasting of the above nature?

'const void *' is 'pointer to const void'. The original code casts
this to 'pointer to const FOO' where FOO is 'pointer to const char'
while your new code casts to 'pointer to non-const FOO'. Your code
casts away const, and while it is valid to do that it is likely that
compilers and code checkers will issue warnings.

$ cat z.c
void f(const void *p) { const char *q = *((const char **)p); }
$ gcc -c -Wcast-qual z.c
z.c: In function 'f':
z.c:1: warning: cast discards qualifiers from pointer target type

-- 
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Oct 13 18:45:41 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.